home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!gatech!nntp.msstate.edu!cee1
- From: cee1@ra.msstate.edu (Charles Evans)
- Subject: Dropping a n from a fprintf()
- Message-ID: <1992Sep11.052108.26159@ra.msstate.edu>
- Organization: Mississippi State University
- Date: Fri, 11 Sep 1992 05:21:08 GMT
- Lines: 48
-
- Ok here is the deal.
-
- Reading in from a textfile with one string per line (variable length, but
- none _too_ long) Then I want to add some strings on either side of the
- read in string and rewrite the new string to a new file line by line. But
- there are some probs.. here is what I have:
-
- FILE *fp1, *fp2;
- char *item; /* also tried stuff like char item[20];,
- same results */
-
- ....
-
- while ((fgets(fp1,20,item)) != 0)
- {
- fprintf(fp2,"I found a %s in my pocket\n", item);
- }
- ...
-
- Ok here is the deal. fgets reads at most 20-1 characters or up to a
- newline.. and if it reaches a newline it adds that to the string along with
- the \0.. So if on the first line of reading in (from fp1) it had "chicken"
- the string in fprintf would be:
-
- ----------------------------------------
- | c | h | i | c | k | e | n | \n | \0 |
- ----------------------------------------
- 0 1 2 3 4 5 6 7 8
-
- but when I printout.. I get this input:
- ----
- I found a chicken
- in my pocket
- ----
-
- I shoots the \n in the fprintf() .. I want it on one line
- so how may I ask can i do it.. I know scanf() has a %[^exclude_chars] con-
- version.. but printf() doesnt seem to. And if I use gets() .. cant read
- from a file
- fscanf(fp1,"%s",item) .. seems to be giving EVERYTIME a Segmentation
- Fault (UNIX) in that line. so we went to fgets.. what can I do to get
- it all on one line.. thanks
-
- --
- +--------------------+-----------------------+------------------------+
- | Charles E. Evans | cee1@ra.msstate.edu | All things are green |
- | iDLE CHATTEr | cee1@MSSTATE.BITNET | unless they are not. |
- +--------------------+-----------------------+------------------------+
-