home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!vnet.ibm.com
- From: russotto@vnet.ibm.com (Matthew T. Russotto)
- Message-ID: <19921118.060506.228@almaden.ibm.com>
- Date: Wed, 18 Nov 92 08:58:34 EST
- Newsgroups: comp.unix.aix
- Subject: Re: Simple EOF problem?
- Disclaimer: This posting represents the poster's views, not those of IBM
- News-Software: UReply 3.0
- References: <BxvzEE.79B@acsu.buffalo.edu>
- Lines: 26
-
- In <BxvzEE.79B@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?
-
- The program is buggy. EOF is not a char value, but you are comparing
- it to one. Are you using the option which makes 'char's unsigned?
- Probably on the SparcStation, it would detect a 0xFF character in the
- file as end of file.
- Try something like
- int tc;
- while ((tc = fgetc(fp))!= EOF)
- buffer[i++] = tc;
-