locate the first occurrence of a given character in a string
#include <string.h> char *strchr( const char *s, int c ); char __far *_fstrchr( const char __far *s, int c );
The strchr() function locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string.
The _fstrchr() function is a data-model-independent form of the strchr() function. It accepts far pointer arguments, and returns a far pointer. It's useful in mixed memory model applications.
A pointer to the located character, or NULL if the character does not occur in the string.
#include <stdio.h> #include <string.h> void main() { char buffer[80]; char *where; strcpy( buffer, "video x-rays" ); where = strchr( buffer, 'x' ); if( where == NULL ) { printf( "'x' not found\n" ); } }
strchr() is ANSI; _fstrchr() is WATCOM.
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
memchr(), strcspn(), strrchr(), strspn(), strstr(), strtok()