Hi,

Very beginner here. I am trying to capture user input. Correct input would be in the form of the letter F followed by 3 digits. i.e. F103. Or the word 'quit' to move back to a higher menu.

So far I have been using:
Code:
#define FNUML 5

fgets(entry, FNUML, stdin);
while(getchar() != '\n')
   continue;
Later I compare the input to the proper format or to 'quit'. That part is working fine.

Where I have a problem is when the user enters something that is shorter than FNUML. i.e. F12 or ABC. Something that is shorter than 5 characters incl the newline. So fgets() is still waiting for one more input. I figured I could try to write my own version and just go character by character with a getchar() but I was hoping there was a better way.

It seems I am always spending more time with input validation than with anything else. I was trying to google this but most stuff I came up with discussed other problems. Sorry for a possible double post.

Thank you!