From the manual
int strcmp(const char *s1, const char *s2);
The strcmp() and strncmp() functions return an integer less than,
equal to, or greater than zero if s1 (or the first n bytes thereof) is
found, respectively, to be less than, to match, or be greater than s2.
So, if both the strings are equal, then strcmp()
returns 0
The ==
is the equal to operator, which checks if the value on both sides are equal. Let's see what the C standard has to say
6.5.9
equality-expression == relational-expression
3 The == (equal to) and != (not equal to) operators are analogous to
the relational operators except for their lower precedence.108) Each
of the operators yields 1 if the specified relation is true and 0 if
it is false. The result has type int. For any pair of operands,
exactly one of the relations is true.
Your code was probably
if( strcmp(pdirection,"up") == 0 )
do_something;
So, if the string stored in pdirection
is equal to "up"
, then the function strcmp()
will return 0 and the == 0
part checks if the value is equal to 0, and if it is equal to 0, then do_something
is done.