當前位置:編程學習大全網 - 編程軟體 - c語言 寫壹個程式讀取文件內有多少個特定的字符

c語言 寫壹個程式讀取文件內有多少個特定的字符

#include?"stdio.h"

#include?"stdlib.h"

int?main()

{

FILE?*fp=NULL;

int?count[26]={0},i;

char?fileName[40]={0};

char?ch;

printf("Please?input?file?name:");

gets(fileName);

if((fp=fopen(fileName,"r"))==NULL)

{

printf("File?read?failed!\n");

exit(0);

}

while((ch=fgetc(fp))!=EOF)

{

if(ch>='A'&&ch<='Z')

count[ch-'A']++;

if(ch>='a'?&&?ch<='z')

count[ch-'a']++;?

}

fclose(fp);

if((fp=fopen("result.dat","w"))==NULL)

{

printf("File?read?failed!\n");

exit(0);

}

fprintf(fp,"character?count\n");

for(i=0;i<26;i++)

fprintf(fp,"%c?%d\n",i+'a',count[i]);

fclose(fp);

}

  • 上一篇:大學生中真的有黑客嗎?
  • 下一篇:無錫道川機器人智能制造有限公司電話是多少?
  • copyright 2024編程學習大全網