Code:
#include <stdio.h>
#include <string.h>
int main ( void ) {
char buff[10];
printf("Type in some long lines\n");
while ( fgets(buff,sizeof buff,stdin) != NULL ) {
int hasNewline = strchr(buff,'\n') != NULL;
printf( "%d %d %s\n", strlen(buff), hasNewline, buff );
}
return 0;
}
./a.out
Type in some long lines
hello world, how are you today
9 0 hello wor
9 0 ld, how a
9 0 re you to
4 1 day
See - if the buffer fills before the \n, then there is no newline appended (but there's always a \0)
If there is a newline, and it fits in the buffer, then fgets() returns at that point as well.