当前位置:网站首页>6-5 统计单词数量(文件)(*)
6-5 统计单词数量(文件)(*)
2022-06-11 17:17:00 【西红柿_码农】
请编写函数,统计英文文章的单词数量。
函数原型
int CountWord(FILE *f);说明:参数 f 为文件指针。函数值为该文件的单词数量。
裁判程序
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int CountWord(FILE *f);
int main()
{
FILE *f;
int n;
f = fopen("Story.txt", "r");
if (!f)
{
puts("文件无法打开!");
exit(1);
}
n = CountWord(f);
if (fclose(f))
{
puts("文件无法关闭!");
exit(1);
}
printf("单词数: %d\n", n);
return 0;
}
/* 你提交的代码将被嵌在这里 */打开 Windows 记事本软件,复制下面的文章内容,保存文件并命名为“Story.txt”。
Story.txt
A Cure for a Headache
One day a man went into a chemist's shop and said, "Have you anything to cure a
headache?"
The chemist took a bottle from a shelf, held it under the gentleman's nose and
took out the cork. The smell was so strong that tears came into the man's eyes
and ran down his cheeks.
"What did you do that for?" he said angrily, as soon as he could get back his
breath.
"But that medicine has cured your headache, hasn't it?" said the chemist.
"You fool," said the man, "It's my wife that has the headache, not me!"
样例输入
(无)
输出样例
单词数: 108
注:一串连续的字母被定义为一个单词。
int CountWord(FILE *f)
{
int count=0;
char a[100];
while(fscanf(f,"%s",a)==1)
{
for(int i=0;a[i];i++){
if(a[i]=='\'')
{
count++;
break;
}
}
count++;
}
return count;
}边栏推荐
- Is the securities account given by qiniu business school safe? Do you charge for opening an account
- LeetCode-384. 打乱数组
- Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
- Sohu tout le personnel a été escroqué, quels problèmes ont été exposés?
- Vscode automatic eslint formatting when saving code
- Authing 背后的计算哲学
- 搜狐全员遭诈骗,暴露哪些问题?
- DFS和BFS笔记(一)基于C语言的广度优先搜索
- Intranet penetration based on UDP port guessing
- 信息安全数学基础 Chapter 2——同余
猜你喜欢

自动化测试-Selenium

ffmpeg硬编解码 Inter QSV

Authing Share|理解 SAML2 协议

Custom or subscription? What is the future development trend of China's SaaS industry?

The use of histogram function in MATLAB

Chip mass production, oppo entering a new era?

Guide to Dama data management knowledge system: percentage of chapter scores

Analyze which should be tested in PMP and ACP with actual cases? Which is more useful?

LeetCode——24. Exchange the nodes in the linked list in pairs (three pointers)

Docker installs mysql5.7 (enable binlog function and modify characters)
随机推荐
《DAMA数据管理知识体系指南》:章节分值占比
Authing Share|理解 SAML2 协议
av_read_frame返回值为-5 Input/output error
C language: use H and C. summary of problems encountered in documents
Derivation of child numbering formula for nodes numbered I in full k-ary tree
Intranet penetration based on UDP port guessing
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod
Classification and method of feature fusion
Song of the sea in 5g Era
Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
How does Sister Feng change to ice?
满k叉树编号为 i 的节点的孩子编号公式推导
Vscode configures eslint to automatically format with an error "the setting is deprecated. use editor.codeactionsonsave instead with a source“
JSP page initial loading method
Difference between select into from and insert into select
LeetCode-384. Scramble array
What problems are exposed when all Sohu employees are cheated?
Association relationship
Dynamic: capturing network dynamics using dynamic graph representation learning
自动化测试-Selenium