So I've testes a few things and I've noticed that with the following code if the user input is Y/y it won't come out of the loop (I call getchar() again to get rid of the \n in the queue so it'll be ready for the next input from the user) :
#include <stdio.h>
#include <stdbool.h>
int main(int argc, char* argv[]) {
for(int i = 0; i < argc; i++)
printf("argv[%d] = %s\n", i, argv[i]);
char name[20];
printf("What's your name ? ");
gets(name);
char lastname[20];
printf("%s what's your last name ? ", name);
fgets(lastname, 20, stdin);
int age;
printf("%s %s what's your age? ", name, lastname);
scanf("%d", &age);
bool exit = false;
char c;
while (!exit) {
printf("Do you wish to exit the program ? (Y/N) ");
c = getchar();
getchar();
if (c == 'Y' || c == 'y')
exit = true;
}
printf("Have a nice day %s %s.\n", name, lastname);
return 0;
}
Can someone enlighten me what is the problem ?