I have written a simple, interactive, program that expects inputs from the user. After it has read a specific input it takes a specific action, but first checks if the user has entered too many commands by reading from the stream any left over characters.
My problem is: if there are no left over characters in the stream it gets stuck until the user presses enter. Is there a way to override this?
This is the function that checks for left over characters in the input stream:
int check_end_of_stream(void){
char c;
c=getchar();
for(; c!='\n' && c!=EOF; c=getchar())
if(c!=' ' || c!=','){
printf("You have written too many statements");
printf(" in your command line!\n");
return 0;
}
return 1;
}
Thank you in advance!
P.S. I am programming in Linux