Find the first occurrence of a character in a string.
LPSTR strchr( LPCSTR lpcszStr, int cc )
Returns a pointer to the first occurrence of a character in a string.
EX1
void strchr_ex1() { int ch = 'O'; char str[] = "Welcome to use Origin!"; printf( "String to be searched: \t%s\n", str ); printf( "Search char:\t%c\n", ch ); /* Search forward. */ char *pCh = strchr( str, ch ); // to search 'O', if found return the position printf("%s\n", pCh); // output "Origin!" if( pCh != NULL ) { int nPos = pCh - str + 1; printf( "Result:\tFirst %c found at position %d\n\n", ch, nPos ); } else printf( "Result:\t%c not found\n" ); }
strrchr
origin.h