Sorry for the probably dumb question, but i wanted to practice loops a bit and came out with this idea.Basically it ask you to enter or not in a loop and when you're in, it ask you for something to do.The problem is that just after i enter the loop it prints two times the printf string before passing to the scanf one and waiting for an input. I can't figure it out. All help is welcome! Here's the code:
#include <stdio.h>
int main()
{
char check = 'a';
char int_check = 'a';
int b = 0;
printf("want to go in? [y or n]\n");
scanf("%c",&check);
if ( check == 'y') {
while (1){
printf("Waiting: \n");
scanf("%c",&int_check);
if ( int_check == 'q'){
printf("You're out, bye!\n");
break;
};
};
} else if ( check == 'n'){
printf("You're not in, see ya!\n");
}else {
printf("Please, type 'y' or 'n'\n");
};
return 0;
}
scanfline in thewhileloop. The destination has a space in it. This is a good solid case for teaching good style when someone is learning a language (e.g., having a space after commas in an argument list, etc.).