当前位置:网站首页>Daily practice of C language - day 3: calculate the number of occurrences of sub strings of strings
Daily practice of C language - day 3: calculate the number of occurrences of sub strings of strings
2022-06-28 11:57:00 【Wang Youduo】
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX_LENGTH 256
int get_sum_child_string(char *str, char *child_str);
int main()
{
char string[MAX_LENGTH];
char child_string[MAX_LENGTH];
printf(" Please enter string and substring respectively - The string does not contain spaces \n");
scanf("%s%s", string, child_string);
printf(" Substring occurrences are %d\n",\
get_sum_child_string(string, child_string));
return 0;
}
/** *@brief from str Search for child_str *@return Number of matched substrings */
int get_sum_child_string(char *str, char *child_str)
{
int sum = 0;
int i = 0;
int str_len = strlen(str);
int child_str_len = strlen(child_str);
/* Judge whether the data is reasonable */
if(str == NULL || child_str == NULL || str_len < child_str_len)
{
return 0;
}
while(strlen(str) >= child_str_len)
{
/* Word string matching */
for(i = 0; i < child_str_len; i++)
{
if(str[i] != child_str[i])
break;
}
/* Match to string */
if(i == child_str_len)
{
sum++;
str += child_str_len;
}
else str++;
}
return sum;
}
边栏推荐
- Simulation of the Saier lottery to seek expectation
- Setinterval, setTimeout and requestanimationframe
- 6.A-B
- QML控件类型:TabBar
- 赛尔号抽奖模拟求期望
- For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?
- Allez, Meta - Cosme, comme prévu, cette chaleur ne durera pas longtemps.
- 《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!
- Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph
- Simple understanding of ThreadLocal
猜你喜欢

Web page tips this site is unsafe solution

Packaging and publishing application of jetpack compose desktop version

Day37 JS note motion function 2021.10.11

Get current system date

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

一套十万级TPS的IM综合消息系统的架构实践与思考

.NET混合开发解决方案24 WebView2对比CefSharp的超强优势

《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!

Fancy features and cheap prices! What is the true strength of Changan's new SUV?

New listing of operation light 3.0 - a sincere work of self subversion across the times!
随机推荐
Packaging and publishing application of jetpack compose desktop version
Chapter 2 do you remember the point, line and surface (2)
JS foundation 10
Day39 prototype chain and page fireworks effect 2021.10.13
Mysql使用max函数查询不到最大值
董宇辉,新东方以及凤凰卫视
Setinterval, setTimeout and requestanimationframe
Day39 prototype chain and page Fireworks Effect 2021.10.13
无法重新声明块范围变量
一套十万级TPS的IM综合消息系统的架构实践与思考
Excel import / export convenience tool class
Day34 JS notes regular expression 2021.09.29
Makefile introduction
Day29 JS notes 2021.09.23
Unity屏幕截图功能
day39 原型鏈及頁面烟花效果 2021.10.13
day39 原型链及页面烟花效果 2021.10.13
How to deploy the software testing environment?
Day36 JS notes ecma6 syntax 2021.10.09
[sciter]:sciter如何使用i18实现桌面应用多语言切换及其利弊