strchr -- Locate First Occurrence of a Character in a String

SYNOPSIS

 #include <string.h>

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

DESCRIPTION

strchr searches the null-terminated string str for the first occurrence of a specific character ch, returning a pointer to the first occurrence, or NULL if the character does not occur in the string.

RETURN VALUE

The return value is a pointer to the first occurrence of the character in the argument string, or NULL if the character is not found. If the search character is the null character ('\0'), the return value addresses the null character at the end of the argument string.

CAUTION

A protection or addressing exception may occur if the argument string is not properly terminated.

See the memscntb function description for information on possible interactions between the strchr, memscntb, or strscntb functions.

EXAMPLE

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

  main()
  {
     char *input;
     char *nl;

     input = "abcdefghijknlmnopqrstuvwxyz";
     if (nl = strchr(input, 'n')) *nl = '0';
     printf("The new line character occurs after %cn", *(nl-1));
  }

 

RELATED FUNCTIONS

memchr, stcpm, strpbrk, strrchr, strscan, strstr

SEE ALSO

String Utility Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.