strstr

Locates the first occurrence in the string pointed to by s1 of the sequence of characters in the string pointed to by s2.

Format

#include  <string.h>

char *strstr  (const char *s1, const char *s2);
Function Variants This function also has variants named _strstr32 and _strstr64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Arguments

s1, s2
Pointers to character strings.

Return Values
Pointer  A pointer to the located string. 
NULL  Indicates that the string was not found. 

Example

    #include <stdio.h>
    #include <string.h>
    
    main()
        {
        static char lookin[]="that this is a test was at the end";
    
        putchar('\n');
        printf("String: %s\n", &lookin[0] );
        putchar('\n');
        printf("Addr: %s\n", &lookin[0] );
        printf("this: %s\n", strstr( &lookin[0] ,"this") );
        printf("that: %s\n", strstr( &lookin[0] , "that" ) );
        printf("NULL: %s\n", strstr( &lookin[0], "" ) );
        printf("was: %s\n", strstr( &lookin[0], "was" ) );
        printf("at: %s\n", strstr( &lookin[0], "at" ) );
        printf("the end: %s\n", strstr( &lookin[0], "the end") );
        putchar('\n');
    
        exit();
        };
    

This example produces the following results:

$ RUN STRSTR_EXAMPLE
String: that this is a test was at the end
Addr: that this is a test was at the end
this: this is a test was at the end
that: that this is a test was at the end
NULL: that this is a test was at the end
was: was at the end
at: at this is a test was at the end
the end: the end
$


Previous Page | Next Page | Table of Contents | Index