HI there,
Currently I am running a loop where fgets is used to read the first 80 characters into a string. This function is being called within a while loop that currently continues until all stdin is read ie if 160 characters are input it will repeat twice (thus printing the two strings), How would I go about clearing the stdin value once the first 80 characters are read? ie that the function will only print one of the strings. It is important to note that the condition of the while loop cannot be changed as it functions as the quit command (when the string returned =="quit" the lop exits).
Thank-you for your time
~qwertyuiop23
EDIT:: Here is a short example of what I am meaning:
Code:
#include <stdio.h>
#include <string.h>
int getstring()
{
char buffer[10];
char *cp = fgets(buffer,10,stdin);
int quit = 0;
if (cp!=NULL) {
if (strncmp(buffer,"quit",4)==0) {
quit = 1;
} else {
quit = 0;
}
}
return quit;
}
int main()
{
do {
printf("\nStill running:");
} while (getstring()!=1);
return 0;
}