Share this page

# strchr

String Manipulation Functions

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

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

string | The string that is searched.
c | The 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.

Copy code

        #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

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: