Advertisement

comparing strings

Started by April 06, 2001 01:12 PM
0 comments, last by slightlywhacked 23 years, 10 months ago
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!
"All your women are belong to me." - Nekrophidius
"Your superior intellect is no match for our puny weapons!"

This topic is closed to new replies.

Advertisement