当前位置:网站首页>[pointer] counts the number of times one string appears in another string
[pointer] counts the number of times one string appears in another string
2022-07-06 14:36:00 【|Light|】
requirement
Make up a function , Count the number of times one string appears in another string .( Use a pointer to achieve )
Code
#include<stdio.h>
#include<string.h>
/* * This function is used to count substrings substr In string str Is the number of times * The number of times after statistics is returned in the form of function value */
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 function
int main()
{
char str[300],substr[50];
int n;
gets(str);
gets(substr);
n=freq_substring(str,substr);
printf("%d\n",n);
}
test
Test input
Good luck, good health, good cheer. I wish you a happy New Year.
ood
Output
3
边栏推荐
- 安全面试之XSS(跨站脚本攻击)
- WEB漏洞-文件操作之文件包含漏洞
- The difference between layer 3 switch and router
- C language file operation
- Captcha killer verification code identification plug-in
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- Sentinel overall workflow
- Based on authorized access, cross host, and permission allocation under sqlserver
- Pointeurs: maximum, minimum et moyenne
- 1.支付系统
猜你喜欢
Network technology related topics
Intel oneapi - opening a new era of heterogeneity
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
关于超星脚本出现乱码问题
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
Proceedingjoinpoint API use
Circular queue (C language)
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
Intranet information collection of Intranet penetration (I)
《统计学》第八版贾俊平第四章总结及课后习题答案
随机推荐
【指针】删除字符串s中的所有空格
“Hello IC World”
循环队列(C语言)
Intranet information collection of Intranet penetration (5)
Database monitoring SQL execution
《英特尔 oneAPI—打开异构新纪元》
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
Intranet information collection of Intranet penetration (I)
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
指针--剔除字符串中的所有数字
Record an edu, SQL injection practice
Hackmyvm target series (2) -warrior
Internet Management (Information Collection)
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
攻防世界MISC练习区(gif 掀桌子 ext3 )
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
What language should I learn from zero foundation. Suggestions
JDBC read this article is enough
On the idea of vulnerability discovery