strchr

String Manipulation Functions

Returns the pointer to the first occurrence of a character in a string.

char *strchr( const char *string, int c);

stringThe string that is searched.
cThe character that is searched for in the string.

Return Values

strchr returns the pointer to the first occurrence of a character in a string. If character is found, returns a pointer to the first occurrence of c in string. If not, it returns NULL.

Example

The following example uses strchr to find the first instance of the character 'x' in the string, string.

    #include <string.h>
    char * string = "His Excellency the Duke of Exeter";
    char * first_x, * last_x;
    first_x = (char *)strchr(string, 'x');
    lr_output_message ("The first occurrence of x: %s", first_x);
    last_x = (char *)strrchr(string, 'x');
    lr_output_message ("The last occurrence of x: %s", last_x);
Example: Output:
Action.c(7): The first occurrence of x: xcellency the Duke of Exeter
Action.c(10): The last occurrence of x: xeter