C语言中部分字符串处理函数

本文通过几个示例展示了 C++ 中使用标准库函数处理字符串的方法,包括查找特定字符、连接字符串、查找子字符串及按指定分隔符切割字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <vector>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
using namespace std;



//strchr函数,查找第一个出现的字符的位置
int main()
{
char p1[] = "adfshfekjfklszi";
char p2 = 'z';
char *p = strchr(p1,p2);
cout<<p<<endl;//zi
}

/*

int main()  //strcat字符串接续函数
{
char ch[30] = {0};
char *p1 = "strcat";
char *p2 = " ";
char *p3 = "strcat";
strcat(ch,p1);
strcat(ch,p2);
strcat(ch,p3);
cout<<ch<<endl;//strcat strcat
}


int main()   //strstr查找字符串中出现字符串二的第一个位置
{
char p1[] = "abaabcadabcbd";
char p2[] = "abc";
char *p = strstr(p1,p2);
cout<<p<<endl;//abcadabcbd
}


int main(int argc,char *argv[])//strtok字符串切割函数,根据传递的参数进行切割
{
int fd = open(argv[1],O_RDONLY);
if(fd == -1)
{
cout<<"error"<<endl;
return 0;
}
char ar[100] = {0};
int n = read(fd,ar,100);
char *p = strtok(ar," ");
while(p)
{
while(*p != '\0')
{
int m = *p - '0';
if(m >= 0 && m < 10)
cout<<m;
p++;
}
cout<<endl;
p = strtok(NULL," ");
}


return 0;
}
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值