2
Contributors
3
Replies
13
Views
3 Weeks
Discussion Span
Last Post by rproffitt
0

From the docs:

The C library function char fgets(char str, int n, FILE *stream) reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.

-> https://www.tutorialspoint.com/c_standard_library/c_function_fgets.htm

So it stops under those conditions. If you want to reveal why you want it to stop or have a C code sample, add that here.

0

I thought newline is equivalent to hitting enter on the keyboard. Is that correct? With this while loop it does not stop when I hit enter. I have to hit Ctrl-D or fill up the buffer to make it stop reading.

while(fgets(line, sizeof line, stdin))
{
}
0

I think you need to read the tutorial again. You have a while() and no check for break, etc.

Remember I do not know what you want to happen but the code you supplied would behave as you said.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.