if(!strcmp(m_edit,"haha");
{
MessageBox("haha");
}
else
{
MessageBox("LOL");
}
is there anything wrong with this code???
how come my result is the "LOL" one even i enter the correct one
im using the VisualC++
Printable View
if(!strcmp(m_edit,"haha");
{
MessageBox("haha");
}
else
{
MessageBox("LOL");
}
is there anything wrong with this code???
how come my result is the "LOL" one even i enter the correct one
im using the VisualC++
strcmp() is telling you that the two strings are not the same. Since one string is a literal, I would suggest you check the contents of the other, because it is clearly not what you think it is!
and strcmp() is case sensitive. so 'm_edit' must contain 'haha', not 'Haha' or 'HAHA' and so on...
can i make it not case sensitive
Hey,
Yer you could convert the string to lowercase before you check it.(the one in the edit box).
Look into the function tolower() and use it before you do the strcmp.
Hope that helps.
TNT
yes, use strcmpi().Quote:
can i make it not case sensitive
how to i use the strcmpi(); ????
or can i do like the word is Chris Sim
then i enter Chris only and it will return mi the result
From MSDN...
Code:#include <string.h>
#include <stdio.h>
char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";
void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
Output
Compare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox
strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2
Adrian what are you doing!?!?!?
Quote:
void main( void )
Watch out or you'll get an angry Prelude in the head :)
The important thing was his quote "From MSDN..."Quote:
Originally posted by ErionD
Adrian what are you doing!?!?!?
Watch out or you'll get an angry Prelude in the head :)
Some of the code on MSDN is ancient.......
>>> Watch out or you'll get an angry Prelude in the head.
LOL. Fordy explained. I'll refer her to Bill!