In C, strchr() searches a C-string for the first matching character. Use single quotes for the character, such as '@'.
You pass the string and the character. Both are required. The result is a pointer into the same string, or NULL when the character is missing. Include <string.h>.
Syntax
Pass the string and the character. Start with this call.
C
strchr(email, '@');
Call
What it does
strchr(email, '@')
Looks for the first '@' in email.
Include <string.h>. Check for NULL before you use the pointer. For the last match, use strrchr().
Library declarations
C
char *strchr(const char *str, int c);
Parameters
Parameter
Description
str
Required. The C-string to search.
ch
Required. The character to find, written in single quotes.
Return Value
Return Value
Description
Pointer
Points to the first match inside the same string.
NULL
Returned when the character is not found.
C Examples
Example 1 — Find the First Match
Search for a character and print from that position. If it is missing, print a clear message instead of crashing.