strchr()函数 和 strrchr() 函数

电脑杂谈  发布时间:2020-02-06 15:00:14  来源:网络整理

strchr函数怎么用_c strchr函数_c strchr函数用法

strchr

定义于头文件 <string.h>

char *strchr( const char *str, int ch );

寻找ch(按照如同(char)ch的形式转化成char后)在str所指向的空终止字节字符串(每个数组都被看做unsigned char)中的首次发生位置。终止的空数组被觉得是字符串的一部分strchr函数怎么用,并且可在寻求'\0'时被找到。

strchr函数怎么用_c strchr函数_c strchr函数用法

若str不是指向空终止字符字符串的指针,则行为已定义。

参数

str - 指向待分析的空终止字符字符串的指针

ch - 要查找的数组

c strchr函数用法_c strchr函数_strchr函数怎么用

返回值

指向str找到的数组的指针strchr函数怎么用,在未找到该字符时返回空指针。

示例

/* strchr example */
#include <stdio.h>
#include <string.h>
int main ()
{
  char str[] = "This is a sample string";
  char * pch;
  printf ("Looking for the 's' character in \"%s\"...\n",str);
  pch=strchr(str,'s');
  while (pch!=NULL)
  {
    printf ("found at %d\n",pch-str+1);
    pch=strchr(pch+1,'s');
  }
  return 0;
}
/*Looking for the 's' character in "This is a sample string"... 
found at 4 
found at 7 
found at 11 
found at 18*/

c strchr函数_strchr函数怎么用_c strchr函数用法

strrchr

定义于头文件 <string.h>

const char *strrchr( const char *str, int ch );

char *strrchr(char *str, int ch );

c strchr函数用法_c strchr函数_strchr函数怎么用

找到最后一次出现的字节ch中的字节串所指向的str.

参数

str - NULL结尾的字节串的指针来进行分析

ch - 搜索字符

返回值

str,或NULL找到的字符的指针,如果没有这样的字符被找到

示例


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-139830-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...