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;
}
*/
#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;
}
*/
相关文章推荐
- C语言中字符串处理函数实现(部分)
- C语言——字符和字符串常用处理函数
- c语言字符串处理函数
- C语言字符串处理函数
- C语言标准库中常见字符串处理函数
- C语言字符串处理函数
- 【C语言】10-字符和字符串常用处理函数
- 《C语言:常用的字符串处理函数总结》
- C语言部分字符串处理代码示例
- C语言中的字符串处理函数
- C语言中字符串处理函数拾锦
- Strsafe.h:更安全的C语言字符串处理函数
- C语言字符串处理函数
- C语言字符串处理函数
- C语言及程序设计提高例程-30 字符和字符串处理函数
- C语言中字符和字符串的处理函数总结
- 更安全的C语言字符串处理函数
- c语言中strchr()字符串处理函数
- C语言实现常见的字符串处理函数
- C语言系列(三)字符串处理函数