[ strstr reference ] states the return value for char * strstr (char *str1,const char *str2 )
is :
A pointer to the first occurrence in str1 of the entire sequence of
characters specified in str2, or a null pointer if the sequence is not
present in str1.
Now for a little more C terminology, when you do :
tmp = strstr(ins, rep)
the main intent of C is to evaluate the expression as a whole and C evaluates it to the return value of strstr(ins, rep)
here. The side effect is assigning this return value to tmp
. The error :
suggest parentheses around assignment used as truth value
is a way gcc helps you to avoid a careless mistake, say typing a=b
instead of a==b
, I believe. Note that in the first case the value of b is used as truth value, but in the second case the result of is a equal b
is used a truth value. By putting a ()
around tmp = strstr(ins, rep)
you give the compiler the green signal to evaluate the value of the expression as truth value.
Side Note :
Putting ()
around tmp = strstr(ins, rep)
makes it a full expression, and full expression is considered as a sequence point. A sequence point is a point in program execution at which all side effects are evaluated before going on to the next step.