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() and _fstrchr() functions locate 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 is most useful in mixed memory model applications.
a pointer to the located character, or NULL if the character does not occur in the string.
memchr(), strcspn(), strrchr(), strspn(), strstr(), strtok()
#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" ); } }
ANSI