Hello,
I have run into this problem before but have always been able to sneak around it, but, now I really have to figure out what I'm doing wrong.
Basically when I enter input that is to big ie...234327432 words, it stays in the buffer, so it always promps the user that their input is to big.
I thought the command;
addressed that issue?Code:while(fgetc(stdin)!='\n');
Any help would be great thanksCode:#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { char size[3]; int a; while(1) { A : printf("Please enter how many words you want: "); fflush(stdout); for (a=0; a<3; a++) { size[a]=fgetc(stdin); if (size[0] == '\n') { printf("Input is empty\n"); goto A; } if (atoi(size) > 100) { printf("Input is too long\n"); while(fgetc(stdin)!='\n'); goto A; } if (size[a] == '\n') break; } break; } printf("You want %d words.", atoi(size)); return 0; }