/*
check if substring is in string or not using C language
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[] = "hello world ,lautturi!";
char needle1[] = "world";
char needle2[] = "lautturi";
if (strstr( str, needle1) != NULL) {
printf(" '%s' is found in string \n",needle1);
}
if (strstr( str, needle2) != NULL) {
printf(" '%s' is found in string \n",needle2);
}
else{
printf("' %s 'is not found in string \n",needle2);
}
return 0;
}Source:www.lautturi.comoutput:
'world' is found in string ' lautturi 'is not found in string Process returned 0 (0x0) execution time : 0.319 s