From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Why won't it change?!? Date: Sun, 6 Jul 1997 12:50:25 +0100 Organization: None Distribution: world Message-ID: References: <5pnu89$6tr$1 AT missing DOT link DOT ca> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 46 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk James Edwin Cooper writes: >main() Pedantic point: that should be 'int main()', and you should put a 'return 0;' at the end of the program... >{ >char letter; >printf("please type a letter: "); >getche(letter); Nooo!!! The getche() function _returns_ the key, it doesn't take the variable as a parameter! You should write 'letter = getche()'. >printf("\nYour letter was "%c, letter); >} > >I think that is what it is, probably a couple mistakes. >Anyway, I fixed the code,etc. and got it to compile and work but only the >first time I use it does it work right. Here is an example: You probably got a couple of warnings while compiling that, though? If not you should put -Wall on your gcc command line, so it will warn you about calls to unprototyped functions. You should include stdio.h and conio.h to get rid of those warnings, after which you'll get an error for the incorrect call to getche(). >Any reason WHY? Same thing happens with random number generators. Even assuming you are calling the RNG correctly (using the return code, not a function argument!) it will always return the same sequence of values unless you seed the generator first, with something like srandom(time(NULL)) (for the random() function, use srand() to seed the rand() generator). That should be covered in any decent C textbook... >P.S. I got these STRAIGHT from a book (with minor changes for DJGPP) so >their is NO mistakes in what I compiled! If that really is the exact code from your book, I suggest you consign it straight to the trashcan. Just because something is in print doesn't make it correct or useful... -- Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ Beauty is a French phonetic corruption of a short cloth neck ornament.