Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add system("exit"); in C

Tags:

c

exit

system

I would like to exit my program with

system("exit");

in C. I compiled my code with gcc and run it via terminal. But somehow the program didn't execute the call to the system to exit. Why is that happened? Because if I did system("clear") it work smoothly

like image 543
giripp Avatar asked Nov 28 '22 09:11

giripp


1 Answers

In C, system() starts a shell and executes the command. exit exits the shell. The expected result would be that nothing happens, what result did you get?

I think what you want is:

#include <stdlib.h>
exit(EXIT_SUCCESS);
like image 70
sverre Avatar answered Dec 06 '22 10:12

sverre