Hint. Try this program to see why strchr() is handy after fgets() and to see which character you should be searching for:
Code:
#include <stdio.h>
int main(void)
{
char buf[10], *p;
printf("Type something: ");
fflush(stdout);
fgets(buf, sizeof(buf), stdin);
// Print the ASCII value before each character entered
for(p = buf;*p;++p)
printf("(%d) %c\n", *p, *p);
return 0;
}
Try entering something less than 9 characters long. Notice anything odd about the last character outputted?
Now try it again, but enter something longer than 8 characters.
Consult an ASCII table if you have to.
Disclaimer: The preceding program and explanation assumes you're in an ASCII environment, which you probably are.