2020年05月11日 23:00 __ _ _ _ _

文章配图

The most wonderful life is not the moment to realize the dream, but to keep
the dream of the process.

人生最精彩的不是实现梦想的瞬间,而是坚持梦想的过程。

题目描述:读取a.txt中文本,统计文本中字母数量。(题目只要求补充部分函数)

样例输入

abc abc

样例输出

6

源代码


#include<stdio.h>#include<string.h>extern void solve();int main(void){    FILE *f=fopen("a.txt","w");    fprintf(f, "%s", "FILE *fp = fopen(a.txt,r);FILE *fpp = fopen(b.txt,w);int a,c;char s[10];");    fprintf(f, "%s", "\n    abc");    fclose(f);    solve();    return 0;}void solve(){    int n,k;//k起记数效果    char a[100];    k=0;    FILE *fp;    fp=fopen("a.txt", "r");    for (n = 0; n < 100; n++) {        if(feof(fp)){//判断文件是否结束,若结束则返回0            break;        }        fscanf(fp, "%c", &a[n]);        if(a[n]=='\0'){//也是起判断作用,可有可无            break;        }        if(a[n]>='A'&&a[n]<='Z'||a[n]>='a'&&a[n]<='z') {            k++;        }    }    printf("%d",k);    fclose(fp);//关闭文件}

运行结果:

文章配图

文章配图

最后的话:刷题要找自己的不足,然后去专攻。

往期推荐:

学计算机,还不知道数据编码?你OUT了 2020-05-10
文章配图

2020年5月编程排行榜:C语言反超Java夺冠 2020-05-05
文章配图

code.blocks最新下载免安装教程及简单入门

2020-04-29


文章配图

公众号:程序员Bob

一个正在学习C语言的人,致力于将C讲得更透彻!

点赞关注谢谢你

长按下图二维码关注,和你一起领悟程序员的魅力。

文章配图

点“ 在看 ” 你懂得

文章配图

预览时标签不可点

阅读




__