www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/01/05:15:23

Date: Wed, 1 Jul 1998 09:55:01 +0200 (MET DST)
From: Federico Spinazzi <federico AT SysPr03 DOT disat DOT unimi DOT it>
To: Fozzy the Bear <fozzy99 AT geocities DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Simple password program
In-Reply-To: <3599C945.3AC1F40B@geocities.com>
Message-ID: <Pine.LNX.3.93.980701092248.23695E-100000@SysPr03.disat.unimi.it>
MIME-Version: 1.0

On Tue, 30 Jun 1998, Fozzy the Bear wrote:

>     if(&name="fozzy")       /* ,&password==bear */

The problem should be here. The = operator is for assignement, like := in
pascal; the equivalence operator is == : if ( A == B) but, you are
assigning, while trying to test for equivalence, an array of char to the
address of name !

I think there are at least 4 ploblems:

1 - = instead of ==;
2 - the use of "foozy": you should have declared char Foozy[] = "foozy";
and then used Foozy, but see 3; I think that declaration is the only point
were you can use a literal string i.e.: you can use it only during a
declaration/inizialization; I've expressed this point very badly because
you can always write things like fprintf(stdout, "foozy") or strcmp(name, 
"foozy");
3 - you think to be able to compare two 'strings' by means of ==, don't
you ?: you can't, you have to use , e.g., the library function strcmp and
its similar: 
	if (strcmp(name, "foozy") == 0)
		/*then they are the same sequence of chars */
4 - the & operator here returns the memory address of a variable, so, how
can you compare it with a 'string' (apple with elefants)?

5 - there should be a libc function that break the echo on the screen
while writting input from keyboard: it could be useful while reading
passwords. I don't remember its name.

I provide here a maybe useful link for better help. DJGPP mailing list is
not direcly related to C problems, even if I also have posted question
like that here (people here is so kind :-)):

C-FAQ:

http://www.eskimo.com/~scs/C-faq/top.html


hope that help,
federico

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019