Chapter Contents

Previous

Next
strstr

strstr



Locate First Occurrence of a String within a String

Portability: ISO/ANSI C conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <string.h>

char *strstr(const char *str1, const char *str2);


DESCRIPTION

strstr scans the input string str1 for the first occurrence of the search string str2 .


RETURN VALUE

strstr returns a character pointer to the first occurrence of the search string in the input string. If the search string cannot be found, strstr returns NULL .


CAUTION

Both arguments must be terminated with the null character; otherwise, a protection or addressing exception can occur.


EXAMPLE

#include <string.h>
#include <stdio.h>

main()
{
   char *text_buffer ="12345-\n67-\n89";
   char *word_break ="-\n";
   char *hyphen;

   hyphen = strstr(text_buffer, word_break);
   printf("The first occurence of \"-\\n\" is after the digit %c\n",
          *(hyphen-1));
}


RELATED FUNCTIONS

strchr , stcpm


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.