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

#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;
}
*/

猜你喜欢

转载自blog.csdn.net/zhanglu_1024/article/details/78998475