当前位置:网站首页>[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
边栏推荐
- 数字电路基础(一)数制与码制
- 网络基础详解
- 函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
- Binary search tree concept
- MySQL interview questions (4)
- 【指针】求解最后留下的人
- Hcip -- MPLS experiment
- Windows platform mongodb database installation
- Intranet information collection of Intranet penetration (4)
- How does SQLite count the data that meets another condition under the data that has been classified once
猜你喜欢
JDBC事务、批处理以及连接池(超详细)
How does SQLite count the data that meets another condition under the data that has been classified once
Network layer - simple ARP disconnection
Solutions to common problems in database development such as MySQL
Intranet information collection of Intranet penetration (I)
数据库多表链接的查询方式
循环队列(C语言)
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
“人生若只如初见”——RISC-V
随机推荐
ES全文索引
【指针】删除字符串s中的所有空格
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
Intel oneapi - opening a new era of heterogeneity
JDBC看这篇就够了
“Hello IC World”
Fundamentals of digital circuit (V) arithmetic operation circuit
Detailed explanation of network foundation
指针:最大值、最小值和平均值
Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
数字电路基础(一)数制与码制
指针 --按字符串相反次序输出其中的所有字符
浅谈漏洞发现思路
Always of SystemVerilog usage_ comb 、always_ iff
How to earn the first pot of gold in CSDN (we are all creators)
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
Realize applet payment function with applet cloud development (including source code)
Hcip -- MPLS experiment