home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!rutgers!modus!systemy!oliver!ugo
- From: ugo@oliver.sublink.org (Ugo Cei)
- Newsgroups: comp.lang.c
- Subject: Re: Dropping a n from a fprintf()
- Message-ID: <1992Sep13.110634.23375@oliver.sublink.org>
- Date: 13 Sep 92 11:06:34 GMT
- References: <1992Sep11.052108.26159@ra.msstate.edu>
- Organization: Oliver System - Pavia ITALY
- Lines: 31
-
- cee1@ra.msstate.edu (Charles Evans) writes:
-
- > char *item; /* also tried stuff like char item[20];,
- > same results */
-
- You should seriously ponder why "char item[20]" is correct and "char
- *item" is not. Go back to the chapter on pointers and arrays.
-
- > while ((fgets(fp1,20,item)) != 0)
-
- I wonder how could this code work in the first place. The "fp1" and
- "item" arguments to "fgets" should be exchanged. Are you typing from
- memory ?
-
- >I shoots the \n in the fprintf() .. I want it on one line
-
- Getting to the point, I have once seen this idiom used to remove the
- occasional '\n' at the end of line obtained via fgets:
-
- strtok(item, "\n");
-
- I did never stop and think about it long enough to verify that it
- should indeed work as expected in all cases. This snippet of code came
- from a reputed source, although I can't remember who it was, so I am
- just using it blindly. Any comments ?
-
- Ugo
-
- --
- Ugo Cei --- Via Colombo 7 - 27100 Pavia - ITALY |
- -- Sublink: ugo@oliver.sublink.org | "Real programs dump core"
-