delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/22/17:30:54

From: Vic <tudor AT cam DOT org>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: "Problem with a text string"
Date: Fri, 22 May 1998 16:55:00 -0400
Organization: Communications Accessibles Montreal, Quebec Canada
Lines: 28
Message-ID: <3565E624.1E64@cam.org>
References: <6k4lhm$6ne$1 AT talia DOT mad DOT ibernet DOT es>
NNTP-Posting-Host: dialup-392.hip.cam.org
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

JOA wrote:
> 
> Hello, the program:
> #include <stdio.h>
> char name[];
> main()
> {
> printf ("Write your name:");
> scanf ("%s",&name);
> if (nombre=="John") printf ("hello John");
> else printf ("Error");
> }
> 
> Always write "Error" if i write "John", but never write "hello John". What
> can i do?

Learn proper C?

this should work better:
#include <stdio.h>
char name[30];
main()
{
printf ("Write your name:");
scanf ("%s",&name);
if (!strcmp(name,"John")) printf ("hello John");
else printf ("Error");
}

- Raw text -


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