您的位置:首页 > 编程语言 > C语言/C++

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

2018-01-07 22:46 471 查看
#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;

}

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: