I have this code:


Note:
boom.ok[1][0] has the character "a" while boom.ok[[tempr[0]][0] contains the string "ay".

if ( strcmp(&boom.ok[1][0],&boom.ok[[tempr[0]][0]) == 1)
printf("Hello");

if ( strcmp(&boom.ok[1][0],&boom.ok[[tempr[0]][0]) == 0)
printf("Hello");

None of these statement prints hello. Why?

What if the return value from strcmp is -1?

What if the return value from strcmp is -1?

Is that possible? Am I right? The only return value of strcmp function is only 0 and 1 when the string or variable compared is not equal and equal?

Yes, it's possible.
The possible values are -1, 0, 1.
...but are actually described (in the documentation) as
Less than zero
Equal to zero
Greater than zero
...and serve specific purposes.

What if the return value from strcmp is -1?

I tried -1 in my statement and it works. Thanks a lot!!!

I think it return 0 if they are equal,
however,
return either a positive or negative value of the difference, can be -2 or 4 5 anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.