strchr -- Search for Character

Format

#include <string.h>
char *strchr(const char *string, int c);

Language Level: ANSI, POSIX, XPG4
strchr finds the first occurrence of a character in a string. The character c can be the null character (\0); the ending null character of string is included in the search.

The strchr function operates on null-terminated strings. The string arguments to the function should contain a null character (\0) marking the end of the string.

Return Value
strchr returns a pointer to the first occurrence of c converted to a character in string. The function returns NULL if the specified character is not found.

Example
This example finds the first occurrence of the character p in "computer program".

#include <stdio.h>
#include <string.h>
#define SIZE 40
int main(void)
{
  char buffer1[SIZE] = "computer program";
  char * ptr;
  int    ch = 'p';
  ptr = strchr( buffer1, ch );
  printf( "The first occurrence of %c in '%s' is '%s'\n",
            ch, buffer1, ptr );
  return 0;
  /********************************************************************
     The output should be:
     The first occurrence of p in 'computer program is 'puter program'
  ********************************************************************/
}


strcat -- Concatenate Strings
strcmp -- Compare Strings
strcpy -- Copy Strings
strcspn -- Compare Strings for Substrings
stricmp -- Compare Strings as Lowercase
strncmp -- Compare Strings
strnicmp -- Compare Strings Without Case Sensitivity
strpbrk -- Find Characters in String
strrchr -- Find Last Occurrence of Character in String
strspn -- Search Strings
wcschr -- Search for Wide Character
wcsspn -- Search Wide-Character Strings
<string.h>