strchr
char *  strchr ( const char * string, int c );
string.h
  cplusplus.com  

Find character in string.
  Returns the first occurrence of c in string.
  The null-terminating character is included as part of the string and can also be searched.

Parameters.

string
Null-terminated string scanned in the search.
c
Character to be found.

Return Value.
  If character is found, a pointer to the first occurrence of c in string is returned.
  If not, NULL is returned.

Portability.
  Defined in ANSI-C.
  ANSI-C++ standard specifies two different declarations for this function instead of the one included in ANSI-C:

const char * strchr ( const char * string, int c );
      char * strchr (       char * string, int c );
  Both have the same behavior as the original declaration.

Example.

/* strchr example */
#include <stdio.h>
#include <string.h>

main ()
{
  char str[] = "This is a sample string";
  char * pch;
  printf ("Looking for 's' character in \"%s\"...\n",str);
  pch=strchr(str,'s');
  while (pch!=NULL)
  {
    printf ("found at %d\n",pch-str+1);
    pch=strchr(pch+1,'s');
  }
  return 0;
}
Output:
Looking for 's' character in "This is a sample string"...
found at 4
found at 7
found at 11
found at 18

See also.
  strrchr, strcspn, strcmp, strstr, memchr


© The C++ Resources Network, 2000