From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: what's the equivalent of for gpp ? Date: 24 Sep 2001 11:29:03 GMT Organization: Cornell University Lines: 46 Sender: asu1 AT cornell DOT invalid (on slip-32-102-40-104.ny.us.prserv.net) Message-ID: References: <01c14445$8cc5f3e0$bc8684d5 AT feta> <01c14449$4c5c3fe0$bc8684d5 AT feta> <3BAED94A DOT E957ABFD AT falconsoft DOT be> NNTP-Posting-Host: slip-32-102-40-104.ny.us.prserv.net X-Trace: news01.cit.cornell.edu 1001330943 26022 32.102.40.104 (24 Sep 2001 11:29:03 GMT) X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu NNTP-Posting-Date: 24 Sep 2001 11:29:03 GMT User-Agent: Xnews/4.06.22 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Tim Van Holder wrote in news:3BAED94A DOT E957ABFD AT falconsoft DOT be: > The main problem is that for a file opened in text mode (the default), > CR/LF pairs are read as a signle LF. So if it's a text file you're > reading, there's a good chance you'll never see a CR. Try using > fopen(file, "rb") instead of fopen(file, "r"). I don't think that is correct advice. The purpose of opening text mode is to transparently treat different line endings as '\n'. It does not change the meaning of a stand-alone CR. The problem with the posted snippet was that it went into an infinite loop if the first character read from the stream was not CR, it went into an infinite loop. Assmuing the OP wanted to get rid of line-endings, not the byte 0x0d, he should open the file in text mode, and use code similar to: #include #include int main(int argc, char *argv[]) { int c; FILE *fin; fin = fopen(argv[1], "rt"); if( fin == NULL ) { perror(argv[1]); exit(EXIT_FAILURE); } while( (c = getc(fin)) != EOF) if( c != '\n' ) putc(c, stdout); return EXIT_SUCCESS; } Try this code on files with Unix and DOS line endings, and you'll see the same behavior. Sinan. -- -------------------------------- A. Sinan Unur http://www.unur.com/