Thursday, 12 January 2012

Strstr Function

#include <stdio.h>
char *strstr(char *string2, char string*1); 
The strstr function locates the first occurrence of the string string1 in the string string2 and returns a pointer to the beginning of the first occurrence.
Return Value
The strstr function returns a pointer within string2 that points to a string identical to string1. If no such sub string exists in src a null pointer is returned.
#include <stdio.h>
int main() 
   char s1 [] = "My House is small";
   char s2 [] = "My Car is green";
   printf ("Returned String 1: %s\n", strstr (s1, "House"));
   printf ("Returned String 2: %s\n", strstr (s2, "Car"));
It will proiduce following result:
Returned String 1: House is small
Returned String 2: Car is green

No comments:

Post a Comment

host gator coupon