当前位置:网站首页>[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
边栏推荐
- 函数:求两个正数的最大公约数和最小公倍
- How to earn the first pot of gold in CSDN (we are all creators)
- Intel oneapi - opening a new era of heterogeneity
- Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
- msf生成payload大全
- sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
- 《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
- 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
- Numpy快速上手指南
- 数字电路基础(五)算术运算电路
猜你喜欢
JDBC看这篇就够了
Intel oneapi - opening a new era of heterogeneity
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
《统计学》第八版贾俊平第三章课后习题及答案总结
Intranet information collection of Intranet penetration (3)
Database monitoring SQL execution
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
New version of postman flows [introductory teaching chapter 01 send request]
Wu Enda's latest interview! Data centric reasons
随机推荐
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
Realize applet payment function with applet cloud development (including source code)
链队实现(C语言)
Constants, variables, and operators of SystemVerilog usage
关于超星脚本出现乱码问题
函数:计算字符串中大写字母的个数
Record once, modify password logic vulnerability actual combat
Overview of LNMP architecture and construction of related services
Mathematical modeling idea of 2022 central China Cup
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
【指针】求字符串的长度
【指针】使用插入排序法将n个数从小到大进行排列
Proceedingjoinpoint API use
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
XSS (cross site scripting attack) for security interview
JDBC看这篇就够了
Uibutton status exploration and customization
内网渗透之内网信息收集(五)