CStrings

I tried to compare 2 CStrings but it doesn't seem to work :

char i[10]="hello";
char f[10]="hello";

if(strcmp(i,f))
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No";
}
It always gives me no as output. Shouldn't it be yes?
No, strcmp() returns one of three values, greater than zero, zero, less than zero. You should always compare the return value to your desired result, a return value of zero means that they compare equally.

http://www.cplusplus.com/reference/cstring/strcmp/
Last edited on
Topic archived. No new replies allowed.