135-1821-9792

C语言字符串查找字符函数 c语言查找字符串的函数

c语言字符串函数有哪些

复制相关函数:memcpy、memmove、strcpy、strncpy

我们提供的服务有:成都网站建设、成都做网站、微信公众号开发、网站优化、网站认证、宝山ssl等。为近千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的宝山网站制作公司

字符串连接函数:strcat、strncat

字符串比较函数:memcmp、strcmp、strcoll、strncmp、strxfrm、

查找函数:memchr、strchr、strcspn、strpbrk、strrchr、strspn、strstr、strtok

其他相关函数:memset、strerror、strlen

c语言字符串的查找用什么函数

用strstr这个函数

包含文件:string.h

函数名: strstr

函数原型:extern char *strstr(char *str1, char *str2);

功能:找出str2字符串在str1字符串中第一次出现的位置(不包括str2的串结束符)。

返回值:返回该位置的指针,如找不到,返回空指针。

编写程序实现在一个字符串中查找指定的字符(请用c语言作答)

#includelt;stdio.hgt;

int main()

{

int i,index,count;

char a,ch,str[80];

scanf("%c\n",a);

i=0;

index=-1;

count=0;

ch=getchar();

for(i=0;ch!='\n';i++){

stri=ch;

count++;

ch=getchar();

}

for(i=0;ilt;count;i++)

if(a==stri)

index=i;

if(index!=-1)

printf("index=%d",index);

else

printf("Not Found");

return 0;

}

扩展资料:

getchar()用法:

getchar()函数的作用是从计算机终端(一般为键盘)输入一个字符。getchar()函数只能接收一个字符,其函数值就是从输入设备得到的字符。

例:

#includelt;stdio.hgt;

int main(void)

{

int c;

/*Note that getchar reads from stdin and

is line buffered;this means it will

not return until you press ENTER.*/

while((c=getchar())!='\n')

printf("%c",c);

return 0;

}

注:可以利用getchar()函数让程序调试运行结束后等待编程者按下键盘才返回编辑界面,用法:在主函数结尾,return 0;之前加上getchar();


网站名称:C语言字符串查找字符函数 c语言查找字符串的函数
文章来源:http://kswsj.com/article/ddsjjsi.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号