Path: utzoo!mnetor!uunet!husc6!rutgers!mtune!mtunx!whuts!picuxa!gp From: gp@picuxa.UUCP (Greg Pasquariello X1190) Newsgroups: comp.unix.wizards Subject: Re: Does fgets(3) really work right? Message-ID: <520@picuxa.UUCP> Date: 23 Mar 88 12:40:55 GMT References: <10900013@bradley> Organization: AT&T Information Systems, Parsippany NJ Lines: 25 Summary: add newline In article <10900013@bradley>, brad@bradley.UUCP writes: > > you check the output, should we not get 15 chars on the first > line? Mine prints the whole thing. > #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); > } Add a '\n' to your printf(). The printf is only printing the first 15 characters, then it does the next fgets. The following printf displays the rest of the characters from that line in the file, but it places them right next to the last string because no newline was encountered or supplied. Greg Pasquariello ihnp4!picuxa!gp