C Programming
Computer Programming

C program to searches a string and returns the pointer to the first occurrence using strstr() function



Write a program in C to searches the given string in the specified main string and returns the pointer to the first occurrence of the given string using strstr() function

\* C program to searches a string and returns the pointer to the first occurrence using strstr() function *\

# include < stdio.h >
# include < string.h >
int   main( )
{

char str[100] ;
char searchString[10] ;
char *result ;
printf ("\n Enter a string : ") ;
scanf("%s", str ) ;
printf("\n Enter a Characher for Search : ") ;
scanf("%s", &searchString ) ;
result = strstr( str, searchString ) ;
printf("\n The substring starting from the given string: %s", result ) ;
return 0 ;

}

Output of Program :

Output of C program to searches a string and returns the pointer to the first occurrence using strstr() function