函数名称:           strchr
函数原型:           char*   strchr(char*   str,char   ch);
函数功能:           找出str指向的字符串中第一次出现字符ch的位置
函数返回:           返回指向该位置的指针,如找不到,则返回空指针
参数说明:           str-待搜索的字符串,ch-查找的字符
所属文件:           <string.h>

#include   <string.h>
#include   <stdio.h>
int   main()
{
        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;
}
 
---------------------------------
 
1.函数的使用
The strchr() function searches for the first occurrence of a string inside another string.
strchr()函数的作用是:返回一个字符在另一个字符串中首次出现的位置到后者末尾的子字符串(大小写敏感)。
This function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found.
如果这个函数执行成功,将返回剩余字符串(存在相匹配的字符);如果没有找到相匹配的字符,则反会False。
This function is an alias of the strstr() function.
这个函数的功能与strstr()函数相类似。
Parameter参数 Description描述
string Required. Specifies the string to search
必要参数。指定需要搜索的字符串
search Required. Specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number
必要参数。指定搜索的对象。如果这个参数是一个数值,那么他将搜索与这个数值的ASCII值相匹配的字符
2.注意点
Note: This function is binary safe.
注意:strchr()函数是二进制精确[binary safe]的。
Note: This function is case-sensitive. For a case-insensitive search, use stristr().
注意:这个函数是区分字母大小写的。如果你想在不区分字母大小写的情况下进行搜索,那么可以使用stristr()函数。
3.使用举例1

函数名: strchr 
功  能: 在一个串中查找给定字符的第一个匹配之处\ 
用  法: char *strchr(char *str, char c); 
程序例: 
#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; 
 } 4.使用举例2:
 char buf[200];
 int cur=m_prj.GetCurSel();//得到Combox控件当前的选项"工作调查|8|9"
 m_prj.GetLBText(cur,buf);//将当前选项的值赋给buf
 char *p,*q;
 q=strchr(buf,'|');//q为|8|9
 memset(xmmc,0,sizeof(xmmc));
 strncpy(xmmc,buf,q-buf);//q的地址减去buf的地址,得到“工作调查“
 p=q;
 q++;
 q=strchr(q,'|');//q为"|9"
 memset(wjbh,0,sizeof(wjbh));
 p++;
 strncpy(wjbh,p,q-p);//得到8
 memset(xmbh,0,100);
 q++;
 strcpy(xmbh,q);//得到9

strchr函数总结相关推荐

  1. C语言strchr()函数(字符串中查找子字符)

    头文件:C 标准库 - <string.h> 描述 C 库函数 char *strchr(const char *str, int c) 在参数 str 所指向的字符串中搜索第一次出现字符 ...

  2. C和指针之strcat函数 strchr函数 strcmp函数 strcpy函数 strnchr函数 strstr函数实现

    1  strcat函数实现 #include <stdio.h> //简单实现strcat函数 char *my_strcat(char *des, const char *src) {i ...

  3. php strchr 截断,PHP strchr() 函数

    w3school 教程 PHP String 函数 查找 "world" 在 "Hello world!" 中的第一次超并返回此字符串的其余个别: echo s ...

  4. strchr()函数的详解与实现

    一)strchr()函数的详解 原型:extern char *strchr(const char *s,char c); 头文件:#include <string.h> 功能:查找字符串 ...

  5. C语言strchr函数

    strchr函数原型:extern char *strchr(const char *s,char c);查找字符串s中首次出现字符c的位置. C语言 char *strchr(const char* ...

  6. strchr()函数用法及其详解

    strchr()函数的使用 定义 char *strchr(const char *s,int c) 如果s字符串包含c字符,该函数返回指向s字符串首次出现的c字符的指针(末尾的空字符也是字符串的一部 ...

  7. strchr()函数与strrchr()函数的实现

    char *strchr(const char *s, int c) 功能: 查找字符串s中首次出现c字符的位置 说明: 返回首次出现c的位置的指针,返回的地址是被查找的字符串指针开始的第一个与c相同 ...

  8. C语言strchr()函数以及strstr()函数的实现

    标准函数库中对strchr()函数的描述: char* strchr(const char* str,int c).特点作用是在字符串str中寻找字符c,如果找到则输出字符c的位置,可以以字符串的形式 ...

  9. C中strchr()函数用法

    strchr()函数包含于头文件:#include<stdio.h>中: 函数原型为:char * strchr(char * str, char/int c); 函数功能为:在字符串st ...

  10. strrchr()和strchr()函数

    文章目录 功能 strrchr() strchr() 程序举例 参考来源链接 所属库 #include<string.h> 功能 strrchr() strrchr函数的作用是: 查找一个 ...

最新文章

  1. Linux学习之三-Linux系统的一些重要配置文件
  2. 【专访】KDD2018主席熊辉教授:数据挖掘与深度学习结合新趋势
  3. 风变编程的python课程怎么样-高效学风变编程Python,解锁不一样的职场进阶之路...
  4. 解决windows显示开启HDR后chrome内截图泛白问题
  5. tomcat 增加运行内存
  6. 【OpenCV】imread读取数据为空
  7. OpenCV中HoughLinesP( )检测直线函数返回的坐标的原点
  8. spring boot 集成 Oracle Access Manager(OAM)单点登录
  9. 南方cass字体样式设置_几种常见的CASS字体异常问题,教你如何解决(附字体下载)...
  10. 155款安卓开源项目源码整理+20个Android必备第三方框架
  11. flyway 社区版本使用团队(企业级)特性ignore-migration-patterns使用
  12. 2008服务器系统开启ftp,2008服务器开启ftp服务
  13. raid缓存策略设置
  14. 类似捕鱼达人的金币效果
  15. Conflux 创始人龙凡教授向浙江省委书记车俊汇报 Conflux 最新研发进展
  16. STM32加密保护工具 | STM32Trust介绍、解决方案
  17. ORA-00933: SQL命令未正确结束 解决办法
  18. IntelliJ IDEA设置修改字体大小与样式
  19. 【ProVerif学习笔记】4:信息安全性质(Security Property)
  20. 双坐标轴echarts

热门文章

  1. 论文阅读”Efficient Deep Embedded Subspace Clustering“(CVPR2022)
  2. PHP定时任务实现执行
  3. JDK、IDEA等安装详解
  4. cnc数控刀具管理对企业的重要性你知道吗?
  5. 质疑潘建伟量子计算机,「九章」量子计算优越性遭北大院士质疑,潘建伟陆朝阳长文回应!网友:隔行如隔山...
  6. SimLab Composer 9 for Mac(3D场景渲染工具)
  7. C++抽象编程——指针(1)——什么是指针?
  8. 老旧小区改造新思路,捷径物业管理系统打造智慧社区,业主都说好-捷径系统
  9. lallallala
  10. DOC命令窗口如何进行复制粘贴操作