From: "Martin Ambuhl" Newsgroups: comp.os.msdos.djgpp Subject: Re: "Problem with a text string" Date: Sat, 23 May 1998 02:24:23 -0400 Organization: Nocturnal Aviation Lines: 43 Message-ID: <6k5pp6$oa4@news-central.tiac.net> References: <6k4lhm$6ne$1 AT talia DOT mad DOT ibernet DOT es> NNTP-Posting-Host: p24.tc2.newyo.ny.tiac.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk JOA wrote in message <6k4lhm$6ne$1 AT talia DOT mad DOT ibernet DOT es>... :Hello, the program: :#include :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? ========= Use strcmp instead of ==. don't use an undefined variable (nombre) don't derefernce unitialized pointers don't use implicit function declarations don't use the evil scanf (don't post non-djgpp questions to comp.os.msdos.djgpp) e.g. #include #include int main(void) { char name[BUFSIZ], *nl; printf ("Write your name: "); fflush(stdout); fgets(name, sizeof name, stdin); if ((nl = strchr(name,'\n'))) *nl = 0; : if (!strcmp(name,John")) printf ("hello John\n"); else printf ("Error\n"); return 0; } ========== : :