comparing strings
How do i compare "char" variables in an if statement (Visual C++)
Thanks,
BAHcows go moomoos go cow
If you have two characters, you can compare them directly:
char x, y;
if (x==y)
foo();
But if you have two arrays of characters, i.e. strings, you need to use the strcmp() function, which returns 0 if the two strings are equal:
char x[50], y[50];
if (strcmp(x, y) == 0)
foo();
I believe it''s in string.h.
-Ironblayde
Aeon Software
Down with Tiberia!![](http://www.aeon-software.com/misc/notiberia.gif)
"All your women are belong to me." - Nekrophidius
char x, y;
if (x==y)
foo();
But if you have two arrays of characters, i.e. strings, you need to use the strcmp() function, which returns 0 if the two strings are equal:
char x[50], y[50];
if (strcmp(x, y) == 0)
foo();
I believe it''s in string.h.
-Ironblayde
Aeon Software
![](http://www.aeon-software.com/misc/notiberia.gif)
![](http://www.aeon-software.com/misc/notiberia.gif)
"All your women are belong to me." - Nekrophidius
![](http://www.aeon-software.com/temp/resist.png)
"Your superior intellect is no match for our puny weapons!"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement