cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
CStrings
CStrings
May 20, 2016 at 8:44pm UTC
MrWolf123
(4)
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?
May 20, 2016 at 8:53pm UTC
jlb
(4973)
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
May 20, 2016 at 8:53pm UTC
Topic archived. No new replies allowed.