C和指针之字符串编程练习11(统计一串字符包含the的个数)
发布日期:2021-06-29 14:10:40 浏览次数:2 分类:技术文章

本文共 522 字,大约阅读时间需要 1 分钟。

1、问题

编写一个函数,对标准的输入进行扫描,并对单词"the"出现的次数进行计数,区分大小写,

输进来的输入可以包含空格字符等等

 

 

 

 

2、代码实现

 

#include 
#include
/**编写一个函数,对标准的输入进行扫描,并对单词"the"出现的次数进行计数,区分大小写,输进来的输入可以包含空格字符等等**/void count_the(char *data){ int count = 0; const char *the = "the"; while ((data = strstr(data, the)) != NULL) { ++count; //指针一定要记得后移动,不然会死循环 ++data; } printf("all has %d count the\n", count);}int main(){ char data[100] = ""; gets(data); count_the(data); return 0; }

 

 

 

 

 

 

 

 

 

3、运行结果

 

./count the The chenyuthe thehello hethe thebaiall has 5 count the

 

 

 

 

 

 

 

转载地址:https://chenyu.blog.csdn.net/article/details/78595909 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:C和指针之字符串编程练习6
下一篇:C和指针之字符串实现my_strrchr(char *str, int ch)的函数

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月12日 14时40分58秒