当前位置:网站首页>【指针】统计一字符串在另一个字符串中出现的次数
【指针】统计一字符串在另一个字符串中出现的次数
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
边栏推荐
- 搭建域环境(win)
- Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
- Hackmyvm target series (2) -warrior
- Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
- Sword finger offer 23 - print binary tree from top to bottom
- Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
- Spot gold prices rose amid volatility, and the rise in U.S. prices is likely to become the key to the future
- 内网渗透之内网信息收集(一)
- 《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
- Mathematical modeling idea of 2022 central China Cup
猜你喜欢
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
网络基础详解
《统计学》第八版贾俊平第四章总结及课后习题答案
网络基础之路由详解
JDBC read this article is enough
Detailed explanation of network foundation routing
Database monitoring SQL execution
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
随机推荐
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
Hackmyvm target series (2) -warrior
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
Binary search tree concept
数据库多表链接的查询方式
MySQL learning notes (stage 1)
sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
Intranet information collection of Intranet penetration (I)
JDBC read this article is enough
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
记一次edu,SQL注入实战
网络层—简单的arp断网
Internet Management (Information Collection)
《统计学》第八版贾俊平第五章概率与概率分布
Intranet information collection of Intranet penetration (5)
Markdown font color editing teaching
Feature extraction and detection 14 plane object recognition
内网渗透之内网信息收集(三)
Intranet information collection of Intranet penetration (4)