Ok, here is an example with fgets():
Code:
#define MAX_INPUT 1024
char buffer[MAX_INPUT];
fgets(buffer,MAX_INPUT,stdin);
Now, fgets will read everything from the standard input (stdin) thus the console until the '\n' is found or MAX_INPUT characters are read. It will store everything in buffer. It will also store the '\n' character.
In any case, you have two approaches.
1) Read only the first char. Thus "yes", "yahoo", "yeah" would all means yes. "No", "neh" will mean No. Anything else will be invalid and the have to type again.
2) They have to enter only one character.
I ll give an example with the first approach.
Code:
#define MAX_INPUT 1024
char buffer[MAX_INPUT];
while (fgets(buffer,MAX_INPUT,stdin) != NULL) {
if (buffer[0] == 'y' || buffer[0] == 'Y') {
doYes();
break;
} else if ((buffer[0] == 'n' || buffer[0] == 'N') {
break;
} else {
printf("Enter (y/n)\n");
}
}
Now, fgets reads the input, saves it to buffer and then you do whatever you want. If neither Y,y,N,n is pressed then the process is repeated. The != null exists just in case there is an error from fgets() in which case NULL is returned.
If the user enters more than MAX_INPUT characters then the result is undefined, but it wont crash or overflow. You can check that also, but I don't think you really care at the moment