Skip to main content
added 107 characters in body
Source Link
DinoCoderSaurus
  • 28.6k
  • 2
  • 12
  • 31

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.

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.

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.

Source Link
DinoCoderSaurus
  • 28.6k
  • 2
  • 12
  • 31

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.