strrchr, wcsrchr, _mbsrchr

来源:互联网 发布:源码偷取 编辑:程序博客网 时间:2024/06/05 08:14

strrchr, wcsrchr, _mbsrchr

Scan a string for the last occurrence of a character.

char *strrchr( const char *string, int c );

char *wcsrchr( const wchar_t *string, int c );

int _mbsrchr( const unsigned char *string, unsigned int c );

Routine Required Header Compatibility strrchr <string.h> ANSI, Win 95, Win NT wcsrchr <string.h> or <wchar.h> ANSI, Win 95, Win NT _mbsrchr <mbstring.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version LIBCMT.LIB Multithread static library, retail version MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns a pointer to the last occurrence of c in string, or NULL if c is not found.

Parameters

string

Null-terminated string to search

c

Character to be located

Remarks

The strrchr function finds the last occurrence of c (converted to char) in string. The search includes the terminating null character.

wcsrchr and _mbsrchr are wide-character and multibyte-character versions of strrchr. The arguments and return value of wcsrchr are wide-character strings; those of _mbsrchr are multibyte-character strings. These three functions behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined _tcsrchr strrchr _mbsrchr wcsrchr

Example

/* STRCHR.C: This program illustrates searching for a character * with strchr (search forward) or strrchr (search backward). */#include <string.h>#include <stdio.h>int  ch = 'r';char string[] = "The quick brown dog jumps over the lazy fox";char fmt1[] =   "         1         2         3         4         5";char fmt2[] =   "12345678901234567890123456789012345678901234567890";void main( void ){   char *pdest;   int result;   printf( "String to be searched: /n/t/t%s/n", string );   printf( "/t/t%s/n/t/t%s/n/n", fmt1, fmt2 );   printf( "Search char:/t%c/n", ch );   /* Search forward. */   pdest = strchr( string, ch );   result = pdest - string + 1;   if( pdest != NULL )      printf( "Result:/tfirst %c found at position %d/n/n",               ch, result );   else      printf( "Result:/t%c not found/n" );   /* Search backward. */   pdest = strrchr( string, ch );   result = pdest - string + 1;   if( pdest != NULL )      printf( "Result:/tlast %c found at position %d/n/n", ch, result );   else      printf( "Result:/t%c not found/n" );}

Output

String to be searched:       The quick brown dog jumps over the lazy fox               1         2         3         4         5      12345678901234567890123456789012345678901234567890Search char:   rResult:   first r found at position 12Result:   last r found at position 30 
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 内衣围带过松怎么办 内衣底围特别紧怎么办 全棉衣服上的油怎么办 高腰牛仔裤腰大了怎么办 新买衣服太硬怎么办 棉麻的衣服发硬怎么办 新衣服太硬怎么办雪纺 衣服硬的咯人怎么办 脖子上的勒痕怎么办 腿上容易出现勒痕怎么办 身上总有内裤印怎么办 内裤穿出了印怎么办 饮水机热水口不出水怎么办 饮水机热水口出水小怎么办 新饮水机热水口出水小怎么办 白钢水桶中间支撑怎么办 17岁想长高应该怎么办 身子瘦但脸胖怎么办 减肥只瘦了胸是怎么办 减肥把胸瘦了怎么办 脸又大又圆怎么办 想长高又想减肥怎么办 孩子做作业精力不集中怎么办 写作业老要睡觉怎么办 孩子写作业精神不集中怎么办 小孩精神不集中要怎么办 注意力不集中上课走神怎么办 注意力不集中总是走神怎么办 孩子注意力不集中走神怎么办 上课老走神注意力不集中怎么办 注意力不集中老走神怎么办 7岁儿童视力0.6怎么办 三岁宝宝注意力不集中怎么办 四岁宝宝注意力不集中怎么办 一直在想一件事怎么办 买的家具味道大怎么办 买的木床有味道怎么办 宝宝拍胸片衣服有扣子怎么办 前扣内衣扣子坏了怎么办 运动内衣穿上平胸怎么办 文胸的海绵变形了怎么办