not getting expected result with fgets
not getting expected result with fgets
Hi, I have the following code which I cannot get to work correctly. The
first printf doesn't show until I enter the name and hit Enter. What am I missing/doing wrong? I'm using Eclipse...
#include <stdio.h> enum {max_char = 20 }; static char name[max_char+1]=""; int main( int argc, char ** argv ) { printf("Type your name: "); fgets(name, max_char, stdin); printf("Your name is %s\n", name); return 0; }I type the name (daniel) on a blank screen and then the result is printed: daniel Type your name: Your name is daniel Thanks for any help you can provide.
8 Oct 12, 4:18AM
Thanks Will,
I had tried the first option and did not work either. I tried the scanf as you suggested, with same results. Still a blank line at the beginning.