strchr

Locates the first occurrence of a specified character in a string (function or macro)

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:String Manipulation

Syntax

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

Parameters

s
(IN) Points to the string containing characters for which to search.
c
(IN) Specifies the character for which to search.

Return Values

strchr returns a pointer to the located character, or NULL if the character does not occur in the string.

Remarks

The strchr function or macro locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating NULL character is considered to be part of the string.

See Also

memchr, strcspn, strrchr, strspn, strstr, strtok

Example

  #include <string.h>  
  #include <stdio.h>  
   
  main ()  
  {  
     char    buffer[80];  
     char    *where;  
     strcpy (buffer, "01234ABCD");  
     where = strchr (buffer, ’x’);  
     if (where == NULL)  
     {  
        printf  (" ’x’ not found\n");  
      } 
   
  }