Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ll-xn!mit-eddie!uw-beaver!cornell!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: C Quirk?? Message-ID: <804@PT.CS.CMU.EDU> Date: 4 Feb 88 20:45:01 GMT References: <1653@ssc-vax.UUCP> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 44 Keywords: Weird_Behavior() Not that this requires a net response, I just like reading my posts :-) > > #include > #include > > main() > { > char ch; > > puts("Enter a Character: "); > > while( (ch = getchar()) ) > { > if( isupper(ch) ) > tolower(ch); > > printf("%c\n", ch); > puts("Enter a Character: "); > } > } You must also read the carriage return. When you type a There are two character out there for you to read, not just one as you might have thought - "a\n". There are a couple of approaches to deal with this. One OS depended would be to read characters as soon as they are typed, hence not requiring the user to type a return. Another probably more applicatable, would be to clear the input line after reading. #define clearline() while (getchar() != '\n') . . . ch = getchar(); clearline(); . . . -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu