Message-ID: <3565E7E9.8C3045E1@imailbox.com> From: "Robert C. Paulsen, Jr." Organization: . MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: "Problem with a text string" References: <6k4lhm$6ne$1 AT talia DOT mad DOT ibernet DOT es> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 26 Date: Fri, 22 May 1998 21:02:43 GMT NNTP-Posting-Host: 209.99.40.70 NNTP-Posting-Date: Fri, 22 May 1998 16:02:43 CDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk JOA wrote: > > 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? C and C++ do not support comparisons of character arrays with the == operator, nor with any of the comparison operators. Instead, use the strcmp() function: ============================================ #include #include char name[80]; // <- note the "80" main() { printf ("Write your name:"); scanf ("%s",&name); if ( strcmp(name,"John") == 0 ) printf ("hello John"); else printf ("Error"); } To ignore case sensitivity, use stricmp(). -- Robert Paulsen ICQ 11815732 http://paulsen.home.texas.net If my return address contains "ZAP." please remove it. Sorry for the inconvenience but the unsolicited email is getting out of control.