Scans a string for the first occurence of a given character
Declaration
char *strchr(const char *s, int c);
char far * far _fstrchr(const char far *s, int c);
Remarks
strchr scans a string in the forward direction, looking for a specific character. It finds the first occurrence of the character c in the string s.
The null-terminator is considered to be part of the string; for example, strchr(strs, 0) returns a pointer to the terminating null character of the string strs.
Return Value
On success, returns a pointer to the first occurrence of the character c in string s.
On error (if c does not occur in s), returns null.
Portability
Routine DOS UNIX Windows ANSI C C++ only
near version yes yes yes yes
far version yes yes
//example
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}