#include<stdio.h>
#include<string.h>
int substring(char *str,char *str1);//函数原型
int main(void)
{
char str[64]={0};
char str1[16]={0};
int i,j,x;
printf("please put the string\n");
gets(str);//输入的原字符串
puts(str);
printf("\n");
printf("please put the string1 \n");
gets(str1);//输入的字符串中的子串
puts(str1);
printf("\n");
i=strlen(str);//原字符串长度
j=strlen(str1);//子串长度
printf("the string lenth is %d\n",i);
printf("the string lenth is %d\n",j);
x=substring(str,str1);
printf("then anwser is %d\n",x);
return 0;
}
int substring(char *str,char *str1)
{
int x=0;
char *p;//任意附个初始值
do{
p=strstr(str,str1);//1.p指针指向strstr的返回值。3.再一次循环到 这里函数的参数发生变化,p重新指向strstr返回值,如此循环。
if(p != NULL) {
str=p+1;//2.str同样指向strstr返回值p的下一个地址。
x=x+1;
}
}
while(p!=NULL);
return x;
}
相关文章
- linux命令统计文件中某个字符串出现的次数
- python对于任意字符串,获取其最大连续字符子串以及重复出现次数
- (C语言)在主函数中输入10个字符串(不等长),用另一函数对它们排序,然后在主函数中输出这10个已排好的字符串(指针数组的方法处理)
- C语言中从键盘输入字符串时的一些问题
- C语言把数字转换为字符串的函数
- 请编写一个程序,输入一个由小写字母和其他字符构成的序列字符串保存在tt中,统计“a”到“z”26个字母各自出现的次数,并依次保存在pp数组中,并输出pp数组内容。
- 从零开始,探索C语言中的字符串-4. ‘\0’
- C语言实现字符串的复制的两种方法
- 利用字符串重复出现的次数,编写一个方法,实现基本的字符串压缩功能 - daocaorendeshijie
- 在python中统计字符串或者列表中某个字符或者数字出现的次数(count函数)