> 其他 >
统计一篇英文文章的英文单词个数
用C语言编写
人气:240 ℃ 时间:2020-06-20 06:21:13
解答
/*
本程序由Turbo C2.0编译通过.英文文章请命名为english.txt并放在Turbo C所在目录下.运行结果以文件方式输出,输出文件result.txt也在Turbo C所在目录下.
word是不同的单词;
count是该单词在文章中出现的次数;
percent是文章中各单词出现的频率.
*/
#include "stdio.h"
main()
{
FILE *fp,*result;
char ch='\0';
char word[1000][20]; /* 最多存1000个不同单词,每个单词在20个字符内. */
int count_word[1000]={0}; /* 每个单词对应个数 */
int i=0,j=0,k=0,flag=2,total=0;
float percent; /* 每个单词出现频率 */
clrscr();
if(((fp=fopen("english.txt","r"))&&(result=fopen("result.txt","w")))==NULL)
{
printf("Can't open file\n");
printf("Press any key to exit...");
getch();
exit(0);
}
printf("\nPlease wait...");
while(!feof(fp))
{
ch=fgetc(fp);
if(ch>='a'&&ch='A'&&ch='A'&&ch
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版