Syntax
#include <string.h> char *strchr(const char *string, int c);Description
strchr finds the first occurrence of a byte in a string. The byte c can be the null byte (\0); the ending null byte 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 byte (\0) marking the end of the string.
strchr returns a pointer to the first occurrence of c in string. The function returns NULL if the specified byte is not found.
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' ****************************************************************************/ }Related Information