From: Eamon Walsh Newsgroups: comp.os.msdos.djgpp Subject: Re: Hi Date: Tue, 10 Feb 1998 22:55:10 -0500 Organization: Erol's Internet Services Lines: 21 Message-ID: <34E1211E.8F9@lan.tjhsst.edu> References: <34E03363 DOT 1A28E21C AT student DOT unsw DOT edu DOT au> Reply-To: ewalsh AT lan DOT tjhsst DOT edu NNTP-Posting-Host: 207-172-57-234.s234.tnt2.ann.erols.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Charbel Sadaka wrote: > > Hi , > I'm Charbel (or just Charlie if you prefer), and would really appreciate > it if you could solve this simple problem I have. > > I've downloaded the c compiler from delorie.com for win95(ieDOS)and have > no problems with it except that I've tried writing a simple program to > read from the stdin and count the number of characters in it using the > following code: > while (ch=getchar( ) != EOF) { > count++ > } Besides the fact that EOF is control Z in dos, not control D, this code won't work because the != operator has higher precedence than the = (assignment) operator. So what the code in the while parentheses says is "if you entered EOF then store false in ch, else store true". You can fix this using parentheses: (ch = getchar()) != EOF) -Eamon Walsh