Exapmple One of the ways.
#include <stdio.h>
#include <stdlib.h>
void end_proc(void){
printf("Quitting the program...\n\n");
exit(0);
}
void input_error_proc(void){
int ch;
printf("ERROR\n");
while((ch = getchar()) != '\n' && ch != EOF);//clear input
}
int main(void){
int program;
while(1){
printf("\n"
"Choose one of the following programs: \n\n"
" (1) Fibonacci Sequence Calculator \n"
" (2) Decimal and Binary Calculator \n"
" (3) Prime Number Calculator \n"
" \n"
"If you want to exit the program, press (e or 0).\n"
"Your choice: ");
if(1==scanf("%d", &program)){//input number
if (program == 0){
end_proc();
} else if(program == 1){
printf ("FIBONACCI SEQUENCE CALCULATOR");
} else if(program==2) {
printf("DECIMAL AND BINARY CALCULATOR");
} else if(program==3) {
printf("PRIME NUMBER CALCULATOR");
} else {
input_error_proc();
}
} else {//input not number
char ch, check;
if(2 == scanf(" %c%c", &ch, &check) && ch == 'e' && check == '\n')
end_proc();
else
input_error_proc();
}
}
return 0;
}
0
solved Exit when press 0 in C [duplicate]