From: "Damian Yerrick" Newsgroups: comp.os.msdos.djgpp Subject: Re: open console into binary mode ? Date: Sun, 26 Sep 1999 14:49:05 -0500 Organization: Rose-Hulman Institute of Technology Lines: 56 Message-ID: <7sltf1$4ta$1@solomon.cs.rose-hulman.edu> References: <7slfup$m1f$1 AT fe2 DOT cs DOT interbusiness DOT it> NNTP-Posting-Host: yerricde.laptop.rose-hulman.edu X-Trace: solomon.cs.rose-hulman.edu 938375457 5034 137.112.205.146 (26 Sep 1999 19:50:57 GMT) X-Complaints-To: news AT cs DOT rose-hulman DOT edu NNTP-Posting-Date: 26 Sep 1999 19:50:57 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Bonifati wrote in message news:7slfup$m1f$1 AT fe2 DOT cs DOT interbusiness DOT it... > i have to write some filter programs which must work for binary files, not > only for text ones. > > i tried to open console into binary mode, but my program > crashes when the input isn't redirect from a file. DOS's console is always in text mode. How would a console (a text input device) be in binary mode? > here an example: > > test.c > ------- > #include > #include > main() ANSI says it should be int main(void) > { > char s[100]; > > fflush(stdin); > setmode(fileno(stdin), O_BINARY); > > gets(s); > puts(s); ANSI says you are missing return 0; All functions that don't return void should return something meaningful. This is especially true for main(), as its return value is passed back to the operating system as a batch file's ErrorLevel value. > } > > C:\> test < infile > ok! it displays it's first line > > C:\> test > the program hangs! > nothing appears if i press some keys and CTRL-Break doesn't work! Check to see if stdin is a console first. IIRC, a console can never be opened in binary mode. Damian Yerrick http://pineight.webjump.com/