I am having a problem with the Enter key or character in the stdin stream messing up following input calls.
let's say I have one input call, so I enter in the stuff. but then takes the Enter key as input for the next input call.
I think in c++ there is cin.ignore()
to do the trick.
I just can't find the C version.
The input methods are getchar()
and gets()
.
Sorry if this is a duplicate. I couldn't find the question that matches mine. thanks for any help!
printf("Do you want to view the lines? ");
int choice = getchar();
while (choice == 'y')
{
char line[80];
printf("What line do you want to see? ");
gets(line);
if (line != "all")
{
n = atoi(line);
printf("Line %d: %s\n",n,list[n]);
}
else
for (int i = 0; i<size; i++)
printf("%s \n",list[i]);
printf("Any more lines? ");
choice = getchar();
}
I admit that this is extremely basic, but still learning .