strchr和strstr 函数
函数原型:extern char *strchr(char *str,char character)
参数说明:str为一个字符串的指针,character为一个待查找字符。
所在库名:#include <string.h>
函数功能:从字符串str中寻找字符character第一次出现的位置。
返回说明:返回指向第一次出现字符character位置的指针,如果没找到则返回NULL。
其它说明:还有一种格式char *strchr( const char *string, int c ),这里字符串是以int型给出的。
实例:
#include<string.h>
#include<stdio.h>
int main()
{
char *str="Hello,I am sky2098,I liking programing!";
char character='k' ; //指定一个字符
char *strtemp;
strtemp=strchr(str,character);
if(strtemp!=NULL)
{
printf("%s ",strtemp);
}
else
{
printf("can not find %c !",strtemp);
}
return 0;
}在VC++ 6.0编译运行:
注意返回字符串包含我们character字符。
我们把下面定义:
char character='k' ; //指定一个字符
改写成:
int character='k' ; //指定一个字符
也同样能够实现。
另外,strstr函数
包含文件:string.h
函数名: strstr
函数原型:extern char *strstr(char *str1, char *str2);
功能:找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。
返回值:返回该位置的指针,如找不到,返回空指针。
strchr和strstr 函数的更多相关文章
- strchr和strstr函数
二者都属于c的库函数 包含在<string.h>函数中 不同的是 : strchr是查找单个字符在串中出现的位置 strstr查找的是字符串在串中出现的位置 看代码: //strchr ...
- strstr 函数用法
strstr 编辑 strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串.如果是,则该函数返回str2在str1中首次出现的地址:否则,返回NULL. C语言函数 编辑 ...
- strstr 函数的实现
strstr函数:返回主串中子字符串的位置后的所有字符. #include <stdio.h> const char *my_strstr(const char *str, const c ...
- strstr函数的用法
C语言函数 编辑 包含文件:string.h 函数名: strstr 函数原型: extern char *strstr(char *str1, const char *str2); 语法: ...
- C语言中strstr函数
头文件:#include <string.h> strstr()函数用来检索子串在字符串中首次出现的位置,其原型为: char *strstr( char *str, char * ...
- leetcode5 Implement strstr() 实现strstr函数功能
Implement strstr() 实现strstr函数功能 whowhoha@outlook.com Question: Implement strstr(). Returns the index ...
- strstr函数与strcmp函数
1.strstr函数主要完成在一个字串中寻找另外一个字串 函数实现工程如下:摘自http://baike.baidu.com/link?url=RwrzOxs0w68j02J2uQs5u1A56bEN ...
- C strstr() 函数
包含文件:string.h 函数名: strstr 函数原型:extern char *strstr(const char *str1, const char *str2); 语法:* strstr( ...
- C语言strstr()函数:返回字符串中首次出现子串的地址
今天又学到了一个函数 头文件:#include <string.h> strstr()函数用来检索子串在字符串中首次出现的位置,其原型为: char *strstr( char *s ...
随机推荐
- K-Means算法:图片压缩
#读取实例图片# from sklearn.datasets import load_sample_image from sklearn.cluster import KMeans import ma ...
- .net core 2.2 修改IdentityUser主键标识类型
.net core2.2,生成WebApi或者MVC项目后,Identity 1.增加ApplicationUser.cs文件,内容如下 public class ApplicationUser : ...
- install postgresql 10 on redhat linux 7 Redhat 安装 postgresql 10
---恢复内容开始--- 1. install linux 2. 切换mirror a. 备份原来的repo 文件, [root@localhost ~]# mv /etc/yum.repos.d/ ...
- [转] ESXI6.5 误将硬盘阵列卡配置为passthru直通模式后, 找不到硬盘的问题
There is no easy way to do it, it seems. So I wanted to say that I couldn't afford to do an upgrade ...
- ipad忘记了锁屏密码,已经越狱了
ipad忘记了锁屏密码,已经越狱了, 已经需要连接itunes了...要是恢复的话,好像就不能越狱了耶... 我叫什么好咧 | 浏览 3330 次 问题暂时关闭 推荐于2016-07-23 11: ...
- Form-encoded method must contain at least one @Field.
https://blog.csdn.net/liunian823/article/details/80290855 记得之前遇到过这个问题,并且记录笔记了,这次再翻笔记,却没有找到...搜索 了下. ...
- scrapy 之自定义命令运行所有爬虫文件
1.在spider文件夹同级目录创建commands python包 2.在包下创建command.py文件 3.从scrapy.commands包下引入ScrapyCommand 4.创建一个类,继 ...
- 二十二、Command 命令模式
原理: 时序图: 代码清单: command.Command public interface Command { void execute(); } command.MacroCommand pub ...
- POJ-3159.Candies.(差分约束 + Spfa)
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 40407 Accepted: 11367 Descri ...
- SSM商城开发学习
功能模块:前端:门户.商品搜索.商品展示.购物车.注册&登录 后端:商品管理.订单管理.cms 上线,bug,维护,停到上线,维护,打包,上线 某一个模块出现bug,停到这个模块 tomcat ...