Mail Archives: djgpp/1997/07/19/19:06:27
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.
*******************************************************************
- Raw text -