int strcmp(char *str1, char *str2){
while(*str1!=0){
if(*str1==*str2){
str1++;
str2++;
}
else
break; //Break when both strings have something different
}
if(*str1==0 && *str2==0)
return 0; //If the while ended and both strings ended, they are equal
else
return -1;
}
What are the data types of x and y?i'm using arduino and i want to compare numbers
like if x=123456 and y=123456 or is the same it will execute a program.
what to use string or char when comparing numbers or letters?
tnx.
if ( !strcmp ( stringOne.c_str (), stringTwo.c_str () ) )
// Your good.
Not unless x and y are C++ string objects.http://www.cplusplus.com/reference/cstring/strcmp/Rich (BB code):if ( !strcmp ( stringOne.c_str (), stringTwo.c_str () ) ) // Your good.
I don't understand what the problem is, stringOne and stringTwo are both string objects from string.h? I personally the same technique and it works fine?Not unless x and y are C++ string objects.
char x [] = "bla";
char y [] = "bla";
if ( !memcmp ( &x, &y, strlen ( bla ) )
// Your good
by Duane Benson
by Jake Hertz
by Duane Benson
by Jake Hertz