strchr, _fstrchr
raw OCR
Scans a string for the first occurrence of a given character.
Defined in header <string.h>
Syntax
#include <string.h>
Near version: char *strchr(const char *s, int c);
Far version: char far * far _fstrchr(const char far *s, int c)
Portability
| DOS | UNIX | Windows | ANSI C | C++ only | |
|---|---|---|---|---|---|
| Near version | ■ | ■ | ■ | ■ | |
| ■ | ■ |
Remarks
strchr scans a string in the forward direction, looking for a specific character, strchr finds the first occurrence of the character c in the string s. The null-terminator is considered to be part of the string, so that, for example,
strchr(strs,0)
returns a pointer to the terminating null character of the string strs.
Return value
strchr returns a pointer to the first occurrence of the character c in s; if c does not occur in s, strchr returns null.
See also
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;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `strchr, fstrchr` read as `strchr, _fstrchr`
Stable link: /3.1/string.h/strchr/
· short form /3.1/strchr/