Reputation: 419
For example, if I made a simple switch-case how would I make the console app close depending on the input? I don't want to use to use break; and skip the loop, I want to close the console altogether.
char choice;
printf("Run random function \n");
printf("Exit \n");
choice = getchar();
fflush(stdin);
switch(choice)
{
case '1':
//randomFunction();
case '2':
//I want this case to exit the console the console
}
Upvotes: 1
Views: 2835
Reputation: 5132
You could call exit()
passing the return value as a parameter, this return value can be checked by the calling process / batch file:
exit(EXIT_SUCCESS); // = 0 = (standard) success
or
exit(EXIT_FAILURE); // = 1 = (standard) failure
or
exit(123); // return a specific value
Documentation for MS-Visual Stuidio
Upvotes: 0