当前位置:网站首页>【指针】统计一字符串在另一个字符串中出现的次数
【指针】统计一字符串在另一个字符串中出现的次数
2022-07-06 09:24:00 【|光|】
要求
编一个函数,统计一字符串在另一个字符串中出现的次数。(用指针实现)
代码
#include<stdio.h>
#include<string.h>
/* * 该函数用来统计子串substr在字符串str中出现的次数 * 统计后的次数以函数值的方式返回 */
int freq_substring(char* str,char* substr)
{
int f=0;
int i,j=0,k,l,l1;
l = strlen(str);
l1 = strlen(substr);
for(i=0;i<l;i++)
{
if(str[i]!=substr[0])
continue;
else
{
for(j=0;j<l1;j++)
{
if(str[i+j] == substr[j])
{
if(j+1 == l1)
f++;
else
continue;
}
else
break;
}
}
}
return f;
}
main函数
int main()
{
char str[300],substr[50];
int n;
gets(str);
gets(substr);
n=freq_substring(str,substr);
printf("%d\n",n);
}
测试
测试输入
Good luck, good health, good cheer. I wish you a happy New Year.
ood
输出
3
边栏推荐
- 小程序web抓包-fiddler
- 移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
- 7-7 7003 combination lock (PTA program design)
- Detailed explanation of three ways of HTTP caching
- How to test whether an object is a proxy- How to test if an object is a Proxy?
- 记一次api接口SQL注入实战
- Web vulnerability - File Inclusion Vulnerability of file operation
- 内网渗透之内网信息收集(一)
- 内网渗透之内网信息收集(三)
- Intranet information collection of Intranet penetration (2)
猜你喜欢
随机推荐
How does SQLite count the data that meets another condition under the data that has been classified once
Ucos-iii learning records (11) - task management
《统计学》第八版贾俊平第二章课后习题及答案总结
JDBC read this article is enough
Proceedingjoinpoint API use
Intranet information collection of Intranet penetration (4)
captcha-killer验证码识别插件
Binary search tree concept
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
我的第一篇博客
Intranet information collection of Intranet penetration (3)
线程的实现方式总结
《统计学》第八版贾俊平第一章课后习题及答案总结
7-8 7104 Joseph problem (PTA program design)
攻防世界MISC练习区(gif 掀桌子 ext3 )
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
SQL injection
How to understand the difference between technical thinking and business thinking in Bi?
Hackmyvm target series (6) -videoclub
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案









