The function signature of strstr is
char *strstr(const char *haystack, const char *needle)
Since you have declared needle a const char*
, you are violating the contract. I recommend further reading in the doc, specifically
These functions return a pointer to the beginning of the substring, or NULL if the substring is not found.
in the context of your if (needle == 0)
statement.
PLEASE NOTE: This answer no longer makes contextual sense because of edits to the orginal question.