strchr, _mbschr, wcschr

De RAD Studio
Aller à : navigation, rechercher

Remonter à String.h - Index


Header File

string.h

Category

Memory and String Manipulation Routines, Inline Routines, C++ Prototyped Routines

Prototype

char *strchr(const char *s, int c);/* C only */

const char *strchr(const char *s, int c);// C++ only

char *strchr( char *s, int c);// C++ only

wchar_t *wcschr(const wchar_t *s, int c);

unsigned char * _mbschr(const unsigned char *s, unsigned int c);

Description

Scans a string for the first occurrence of a given character.

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.

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.

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;
 }



Portability



POSIX Win32 ANSI C ANSI C++

strchr

+

+

+

+

_mbschr

+

wcschr

+

+

+