当前位置:网站首页>【指针】统计一字符串在另一个字符串中出现的次数
【指针】统计一字符串在另一个字符串中出现的次数
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
边栏推荐
- 网络层—简单的arp断网
- 7-5 staircase upgrade (PTA program design)
- This article explains in detail how mockmvc is used in practical work
- Binary search tree concept
- "Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
- 《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
- New version of postman flows [introductory teaching chapter 01 send request]
- 7-14 error ticket (PTA program design)
- [paper reproduction] cyclegan (based on pytorch framework) {unfinished}
- sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
猜你喜欢

Windows platform mongodb database installation

《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案

Only 40% of the articles are original? Here comes the modification method

攻防世界MISC练习区(gif 掀桌子 ext3 )

How to turn wechat applet into uniapp

Chain team implementation (C language)

《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案

内网渗透之内网信息收集(二)

Build domain environment (win)

《统计学》第八版贾俊平第四章总结及课后习题答案
随机推荐
Hackmyvm Target Series (3) - vues
Middleware vulnerability recurrence Apache
Network layer - simple ARP disconnection
Applet Web Capture -fiddler
JDBC transactions, batch processing, and connection pooling (super detailed)
Library management system
DVWA (5th week)
Hackmyvm target series (3) -visions
Windows platform mongodb database installation
7-6 local minimum of matrix (PTA program design)
Hcip -- MPLS experiment
XSS unexpected event
Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
Load balancing ribbon of microservices
Low income from doing we media? 90% of people make mistakes in these three points
Uibutton status exploration and customization
[issue 18] share a Netease go experience
Intranet information collection of Intranet penetration (5)
Hackmyvm target series (7) -tron
Realize applet payment function with applet cloud development (including source code)