From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Help with scanf() Date: Sat, 19 Jul 1997 09:46:15 -0400 Organization: Cornell University http://www.cornell.edu Lines: 51 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <33D0C527.39FF@cornell.edu> References: <4GFM1XAs28zzEwrp AT netbook DOT demon DOT co DOT uk> Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0013.cit.cornell.edu 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 James MacDonald wrote: > > At the moment I'm using scanf() - I need to read a value from the > keyboard and compare it with a generated one made by a program. > my first advice is to get a book an C. you can also try steve summit's tutorial at: http://www.eskimo.com/~scs/cclass/cclass.html > char * enter; you have declare enter to be a char pointer. you have not initialised it to pint to a valid memory location. since you seemed to have declared it globally, it will be initialized to 0. > scanf("%s", enter); > printf("Entered string : %s", enter); you are probably running this under windows, right? try running it under plain dos with cwsdpmi and see what happens. it will most likely crash because you are trying to write to address 0 with that scanf statement. anyway, enter is still NULL, so, printf prints that. > if (enter == chalcrypt) printf("it worked!"); you cannot compare strings like this in C. who told you you could learn programming without reading anything? please make everyone a favour and: i. consider getting a book on C ii. at least take a look at the tutorial i mentioned iii. post basic C programming questions to comp.lang.c or comp.lang.c.moderated or alt.comp.lang.learn.c-c++ > Is there an easier way to read the keyboard? > I've tried gets() but I've got stuck there too :( no wonder. in any case, i find reading text line by line using fgets() and parsing it later on much easier. but you have some reading to do before that. -- Sinan ******************************************************************* A. Sinan Unur WWWWWW |--O+O mailto:sinan DOT unur AT cornell DOT edu C ^ http://www.people.cornell.edu/pages/asu1/ \ ~/ Unsolicited e-mail is _not_ welcome, and will be billed for. *******************************************************************