delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/12/22:15:35

Newsgroups: comp.os.msdos.djgpp
From: "A. Jans-Beken" <jabe AT oce DOT nl>
Subject: Re: why don't this work
Message-ID: <350818AA.7A9D@oce.nl>
Sender: news AT oce DOT nl (The Daily News @ nntp01.oce.nl)
Organization: Océ-Nederland B.V.
References: <34F79C17 DOT 71DC AT sainet DOT net>
Mime-Version: 1.0
Date: Thu, 12 Mar 1998 17:17:30 GMT
Lines: 42
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

shifter wrote:
> 
> #include <stdio.h>
> 
> main()
> {
> char *i;
> char *password;

OOPS----^^^^^^^^
password is a pointer but points to nothing.
char *password = "xxxxxxxxxxxxxxxxxx"; works...

> 
>    clrscr();
>    printf ("Input a password:");
>    gets(password);

OOPS------^^^^^^^^ 
password must be allocated. With my version of initialization 
it will work (password shorter then number of x's).

>    printf("you typed:%s\n",password);
>    do{
>    printf ("Input a password:%s:",i);
>    }while (gets(i) != password);

OOPS--------------^
Same problem for i.
OOPS---------^^^^^^^^^^^^^^^^^^^
Comparing strings doesn't work this way in C.
Should be "strcmp(gets(i), password)"

>    printf("you got it!!!");
>    exit(0);
> }
> 
> i'm trying to get it to break out of loop with the correct password
> what am i doing wrong?
> ralph <shifter AT sainet DOT net>

greetings

- Raw text -


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