#include <stdio.h>
#define MAXLINE 4096
int
main(int argc, char **argv)
{
char *s;
char buf[MAXLINE];
s = fgets(buf, MAXLINE, stdin); // here, if replaced with read(0, buf, MAXLINE);
return 0;
}
Input is:12ctrl+d
fgets
doesn't return until input ctrl+d again(That is: 12ctrl+dctrl+d
). Why doesn't fgets return when it encounts the firstEOF
? It seems 12ctrl+d
doesn't work.But when
s = fgets(buf, MAXLINE, stdin);
is replaced withread(0, buf, MAXLINE);
read
will return(input is also: 12ctrl+d
).