Web | This Site

Learning C
C Function References
C Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | About TP |  | Advertising

# C - strstr function

## Synopsis:

    #include <stdio.h>

    char *strstr(char *string2, char string*1);

## Description:

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.

## Example

    #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

Advertisement

Online Image Processing

Indian Baby Names