0

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?

Edited by jodzjcm: grammar

3
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by Ab000dy_85
Featured Replies
  • What if the [URL="http://www.cplusplus.com/reference/clibrary/cstring/strcmp/"]return value[/URL] from strcmp is -1? Read More

  • Yes, it's possible. The possible values are -1, 0, 1. ...but are actually described ([URL="http://www.elook.org/programming/c/strcmp.html"]in the documentation[/URL]) as Less than zero Equal to zero Greater than zero ...and serve specific purposes. Read More

0

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?

1

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.

Edited by thines01: n/a

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.