| Functions | |||||||||||||||||||||||||||||||||||||||||
| Character manipulation | |||||||||||||||||||||||||||||||||||||||||
| Conversions to and from numeric formats | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String manipulation | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String examination | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Memory manipulation | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Miscellaneous | |||||||||||||||||||||||||||||||||||||||||
(C11)(C11) | |||||||||||||||||||||||||||||||||||||||||
Defined in header <string.h> | ||
char* strchr(constchar* str,int ch); | (1) | |
/*QChar*/*strchr(/*QChar*/*str,int ch); | (2) | (since C23) |
T be an unqualified character object type.str is of typeconst T*, the return type isconstchar*.str is of typeT*, the return type ischar*.The behavior is undefined ifstr is not a pointer to a null-terminated byte string.
Contents |
| str | - | pointer to the null-terminated byte string to be analyzed |
| ch | - | character to search for |
Pointer to the found character instr, or null pointer if no such character is found.
#include <stdio.h>#include <string.h> int main(void){constchar*str="Try not. Do, or do not. There is no try.";char target='T';constchar* result= str; while((result= strchr(result, target))!=NULL){printf("Found '%c' starting at '%s'\n", target, result);++result;// Increment result, otherwise we'll find target at the same location}}
Output:
Found 'T' starting at 'Try not. Do, or do not. There is no try.'Found 'T' starting at 'There is no try.'
| searches an array for the first occurrence of a character (function)[edit] | |
| finds the last occurrence of a character (function)[edit] | |
| finds the first location of any character in one string, in another string (function)[edit] | |
C++ documentation forstrchr | |