Path: utzoo!mnetor!uunet!husc6!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.unix.wizards Subject: Re: Does fgets(3) really work right? Message-ID: <799@cresswell.quintus.UUCP> Date: 23 Mar 88 05:56:39 GMT References: <10900013@bradley> Organization: Quintus Computer Systems, Mountain View, CA Lines: 35 Summary: yes it does In article <10900013@bradley>, brad@bradley.UUCP writes: : A student here pointed this out to me, is this a bug? I checked : it out on our 3B15 (V5), VAX 11/750 (4.3) and IBMPC (VENIX/86 2.0). : you check the output, should we not get 15 chars on the first : line? Mine prints the whole thing. : ========cut here for file named "in"========= : 12345678901234567890 : 12345 : aaaaa : ========cut here for "temp.c"============= : #include : : main() : { : char str[15], *cp; : FILE *fp; : : fp = fopen("in","r"); : while((cp = fgets(str, 15, fp)) != NULL) : printf("%s", str); : fclose(fp); : exit(0); : } If you compile and run this program, the output looks exactly like "in". But that's what it is supposed to do. To see what is happening, change the printf() line to printf("{%s}", str); and when you run the program the output is {12345678901234}{567890 }{12345 }{aaaaa } Better yet, read the manual page for fgets(). The whole point of using fgets() is that you don't lose anything.