#include <stdio.h>
#include <string.h>
int main() {
char a[100], b[100];
char *ret;
scanf("%[^\n]s", a);
scanf("%[^\n]s", b);
ret = strstr(a, b);
if (ret != NULL)
printf("its a substring");
else
printf("not a substring");
return 0;
}
My aim was to check whether a substring is present in the parent string in the string or not. I learned about the strstr()
function from here.
I have previously used %[^\n]s
in my codes before and they worked well.
But, in this case as soon as I hit return/enter after typing one string, the output is not a substring
.
What is it that I am doing wrong?