Use strchr to search a string

Syntax

C strchr function has the following syntax.

char *strchr(const char *str, int ch);

C strchr function is from header file string.h.

Description

C strchr function returns a pointer to the first occurrence of ch in *str or a null pointer if not found.

Example

Use C strchr function to search a string.


#include <stdio.h>
#include <string.h>
int main(void)
{//from w ww.  jav  a  2  s .c  om
  char *p;

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

  return 0;
}

The code above generates the following result.





















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