home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ki.com!dwatts
- From: dwatts@ki.com (Dan Watts)
- Newsgroups: comp.unix.aix
- Subject: Re: Simple EOF problem?
- Message-ID: <1270@ki.com>
- Date: 18 Nov 92 16:57:42 GMT
- References: <BxvzEE.79B@acsu.buffalo.edu> <1992Nov18.074916.2886@aragorn.unibe.ch>
- Organization: ki Research, Inc
- Lines: 33
-
- In article <1992Nov18.074916.2886@aragorn.unibe.ch> haedener@iacrs1.unibe.ch writes:
- |In article <BxvzEE.79B@acsu.buffalo.edu>, vidya-v@acsu.buffalo.edu (vidyaranya) writes:
- ||>
- ||> The following piece of code FAILS to detect End of File
- ||> under AIX(i dont know the version currently!) running on
- ||> an IBM PowerServer 970.
- ||> ------
- ||> char buffer[2048];
- ||> int i;
- ||> FILE *fp;
- ||>
- ||> i=0;
- ||> while( (buffer[i++]=fgetc(fp))!= EOF )
- ||> ;
- ||> ------
- ||> Exactly same piece of code runs on a SparcStationIPC running
- ||> SunOS 4.1.2 .
- ||>
- ||> What could be the problem?
- |
- |fgetc returns int.
- |EOF is (-1).
-
- As mentioned above, fgetc returns int and EOF is -1. On AIX, chars
- are *not* signed. So, the -1 gets truncated to 0xFF to fit into
- buffer[]. The 255 is then compared to -1 and sure enough, they're
- not equal.
-
- --
- ######################## Have A Nice Nude Day #########################
- # EMail: dwatts@ki.com UUCP: ...!uunet!ki.com!dwatts Dan Watts #
- # Voice: 410 290 0355 FAX: 410 290 0397 ki Research, Inc. #
- # The Bill Of Rights: Void Where Prohibited by Law. Vote Libertarian ##
-