I am programming in C. For some reason is just skips over my fgets and runs the code afterwards and I don't know why.
char content[256];
printf("What do you want it to say?\n");
fgets(content, 256, stdin);
I am programming in C. For some reason is just skips over my fgets and runs the code afterwards and I don't know why.
char content[256];
printf("What do you want it to say?\n");
fgets(content, 256, stdin);
Have you tried flushing stdin? You may have a newline char caught in it that is causing your fgets to return instantly.
This question references a good way to flush the stdin
Recall that I/O can be buffered. If there is anything waiting in the input buffer when your function is called, it will be read in. In the event that the first character in the buffer is a '\n'
, the function will return immediately and appear to gather no input. Ensure that there is nothing in the input buffer before calling fgets()
.
char content[256];
printf("What do you want it to say?\n");
while ( getchar() != '\n');
fgets(content, 256, stdin);
OR did you try this...
char content[256];
printf("What do you want it to say?\n");
fgets(content, 256, stdin);