Hi everyone.
I'm working with string functions, but I have a trouble with strstr(). Here is the code that works:
Code:
char text[] = "one two three";
char substring[] = "two";
if(strstr(text, substring))
puts("The string sought was found");
else
puts("The string sought was not found");
This is the code that doesn't work:
Code:
#define TEXT_LEN 100
#define SUBSTRING_LEN 40
char text[TEXT_LEN];
char substring[SUBSTRING_LEN];
printf("Enter the text to be searched:\n");
fgets(text, TEXT_LEN, stdin);
printf("Enter the string sought:\n");
fgets(substring, SUBSTRING_LEN, stdin);
if(strstr(text, substring))
puts("The string sought was found");
else
puts("The string sought was not found");
Why strstr() returns NULL even when substring is in text?
I'am working on a GNU/linux system.
Thanks.