今天主要是承接昨天的字符函数学习
加注头文件 #include<string.h>
一般带n的就是需要限制长度
拼接函数 strcat(a,b)
(a,b) b接在a后面
char src[10] = "hello ";
char cc[30] = "xyh ";
strcat(src,cc);//
printf("%s\n",src);
strncat(cc,src,5); //将src前?个加入cc
printf("%s\n",cc);
比较函数 strcmp
比较两个函数大小?前比后,大非零,小为负
char s[10] = "happy";
char a[10] = "xianxian";
int ret = strcmp(s,a);
printf("%d\n",ret);
int ret = strncmp(s,a,1);
printf("%d\n",ret);
切割字符串的函数strtok
分割出每个单词
char s[20] = "this is main";
char *ps = NULL;
ps = strtok(s," ");
puts(ps);
while(ps!=NULL){
ps = strtok(NULL," ");
printf("%s\n",ps);
查字母第一次出现的位置 strchr
// char s[20] = "hello world";
// char a ='o';
// char *p = strchr(s,a);//找字母第一次出现的位置
// printf("%s\n",p);
// printf("%p\n",s);
// printf("%p\n",p);
依次检索字符串 strpbrk
// char s[20] = "hello world";
// char ch[3] = "orl";
// int a = 111;
// char *p;
// p = strpbrk(s,ch);
// printf("%s\n",p);
// printf("%p\n",p);
确定字符串首次出现的位置 strstr
// char s[20] = "hello world";
// char ch[1000] = "llo";
// int a = 111;
// char *p;
// p = strstr(s,ch);
// printf("%s\n",p);
// printf("%p\n",p);