home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13274 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  1.5 KB

  1. Path: sparky!uunet!ogicse!usenet.coe.montana.edu!uakari.primate.wisc.edu!eng.ufl.edu!whale!zzang
  2. From: zzang@whale.uucp (Zhuo Zang[~{j0WA~}])
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help! what's wrong with this program?
  5. Message-ID: <1992Sep6.152442.25878@eng.ufl.edu>
  6. Date: 6 Sep 92 15:24:42 GMT
  7. Article-I.D.: eng.1992Sep6.152442.25878
  8. References: <1992Sep6.041410.16388@eng.ufl.edu>
  9. Sender: news@eng.ufl.edu (Usenet Diskhog System)
  10. Distribution: usa
  11. Organization: University of Florida
  12. Lines: 46
  13.  
  14. In article <1992Sep6.041410.16388@eng.ufl.edu> zzang@whale.uucp (Zhuo Zang[~{j0WA~}]) writes:
  15. >Hello,
  16. >I try to push char c onto buf, and then
  17. >print out the buf.
  18. >But the following codes don't work.
  19. >After compilation, I use
  20. >> foo <foo.c
  21. >nothing printed out.
  22. >
  23. >Could someone tell me why ?
  24. >
  25. >Thanks in advance !
  26. >--------- foo.c ----------
  27. >#include <stdio.h>
  28. >char *sp, buf[BUFSIZ], c;
  29. >main()
  30. >{
  31. >  sp = buf;
  32. >  while ((c=getchar())!=EOF) pushc(c,sp);
  33. some netter remind me that getchar() should return int not char,
  34. so I put casting c=(int)getchar().
  35. and it still doesn't work.
  36. if I dont use ++ in pushc(), and use ++ here, pushc(c,sp++).
  37. the program works just fine. (even without the casting (int)getchar()).
  38. so I doubt this is a pitfall.
  39. >  *sp = '\0';
  40. >
  41. >  puts(buf);
  42. >  return;
  43. >}
  44. >
  45. >pushc(char c, char *bp)
  46. >{
  47. >  *bp++ = c;
  48. >  return;
  49. >}
  50. >-- 
  51. >Zhuo Zang[~{j0WA~}]
  52. >Department of Statistics
  53. >University of Florida            Email: zzang@stat.ufl.edu
  54.  
  55.  
  56. -- 
  57. Zhuo Zang[~{j0WA~}]
  58. Department of Statistics
  59. University of Florida            Email: zzang@stat.ufl.edu
  60.