C strstr function searches sub string

Syntax

C strstr function has the following syntax.

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

C strstr function is from header file string.h.

Description

C strstr function returns a pointer to the first occurrence of *str2 in *str1 or a null pointer if there str2 is not part of str1.

It returns a null pointer if no match is found.

Example

Use C strstr function to search sub string.


#include <string.h>
#include <stdio.h>
//from  w  ww .ja v a2s.c om
int main(void)
{
  char *p;

  p = strstr("this is a test", "is");
  printf(p);

  return 0;
}




















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h