home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!usenet.coe.montana.edu!uakari.primate.wisc.edu!eng.ufl.edu!whale!zzang
- From: zzang@whale.uucp (Zhuo Zang[~{j0WA~}])
- Newsgroups: comp.lang.c
- Subject: Re: Help! what's wrong with this program?
- Message-ID: <1992Sep6.152442.25878@eng.ufl.edu>
- Date: 6 Sep 92 15:24:42 GMT
- Article-I.D.: eng.1992Sep6.152442.25878
- References: <1992Sep6.041410.16388@eng.ufl.edu>
- Sender: news@eng.ufl.edu (Usenet Diskhog System)
- Distribution: usa
- Organization: University of Florida
- Lines: 46
-
- In article <1992Sep6.041410.16388@eng.ufl.edu> zzang@whale.uucp (Zhuo Zang[~{j0WA~}]) writes:
- >Hello,
- >I try to push char c onto buf, and then
- >print out the buf.
- >But the following codes don't work.
- >After compilation, I use
- >> foo <foo.c
- >nothing printed out.
- >
- >Could someone tell me why ?
- >
- >Thanks in advance !
- >--------- foo.c ----------
- >#include <stdio.h>
- >char *sp, buf[BUFSIZ], c;
- >main()
- >{
- > sp = buf;
- > while ((c=getchar())!=EOF) pushc(c,sp);
- some netter remind me that getchar() should return int not char,
- so I put casting c=(int)getchar().
- and it still doesn't work.
- if I dont use ++ in pushc(), and use ++ here, pushc(c,sp++).
- the program works just fine. (even without the casting (int)getchar()).
- so I doubt this is a pitfall.
- > *sp = '\0';
- >
- > puts(buf);
- > return;
- >}
- >
- >pushc(char c, char *bp)
- >{
- > *bp++ = c;
- > return;
- >}
- >--
- >Zhuo Zang[~{j0WA~}]
- >Department of Statistics
- >University of Florida Email: zzang@stat.ufl.edu
-
-
- --
- Zhuo Zang[~{j0WA~}]
- Department of Statistics
- University of Florida Email: zzang@stat.ufl.edu
-