home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / aix / 11682 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  1.4 KB

  1. Path: sparky!uunet!ki.com!dwatts
  2. From: dwatts@ki.com (Dan Watts)
  3. Newsgroups: comp.unix.aix
  4. Subject: Re: Simple EOF problem?
  5. Message-ID: <1270@ki.com>
  6. Date: 18 Nov 92 16:57:42 GMT
  7. References: <BxvzEE.79B@acsu.buffalo.edu> <1992Nov18.074916.2886@aragorn.unibe.ch>
  8. Organization: ki Research, Inc
  9. Lines: 33
  10.  
  11. In article <1992Nov18.074916.2886@aragorn.unibe.ch> haedener@iacrs1.unibe.ch writes:
  12. |In article <BxvzEE.79B@acsu.buffalo.edu>, vidya-v@acsu.buffalo.edu (vidyaranya) writes:
  13. ||> 
  14. ||> The following piece of code FAILS to detect End of File
  15. ||> under AIX(i dont know the version currently!) running on
  16. ||> an IBM PowerServer 970.
  17. ||> ------
  18. ||>     char    buffer[2048];
  19. ||>     int    i;
  20. ||>     FILE    *fp;
  21. ||> 
  22. ||>     i=0;
  23. ||>         while( (buffer[i++]=fgetc(fp))!= EOF )
  24. ||>          ;
  25. ||> ------
  26. ||> Exactly same piece of code runs on a SparcStationIPC running
  27. ||> SunOS 4.1.2 .
  28. ||> 
  29. ||> What could be the problem?
  30. |
  31. |fgetc returns int.
  32. |EOF is (-1).
  33.  
  34. As mentioned above, fgetc returns int and EOF is -1.  On AIX, chars
  35. are *not* signed.  So, the -1 gets truncated to 0xFF to fit into
  36. buffer[].  The 255 is then compared to -1 and sure enough, they're
  37. not equal.
  38.  
  39. -- 
  40. ######################## Have A Nice Nude Day #########################
  41. # EMail: dwatts@ki.com  UUCP: ...!uunet!ki.com!dwatts  Dan Watts      #
  42. # Voice: 410 290 0355   FAX:  410 290 0397          ki Research, Inc. #
  43. # The Bill Of Rights: Void Where Prohibited by Law. Vote Libertarian ##
  44.