前往
大廳
主題

C/C++紀錄二十.<<檔案處理>> 2018/10/16

艾倫D索妮雅 | 2021-06-08 19:56:24 | 巴幣 0 | 人氣 74

//設:資料檔在  D:\檔案處裡\c++.txt
//資料內容:How are you.
//                thank you.
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define len 100
using namespace std;
int main()
{
FILE *fptr;
int count,i,j,n;
char fpath[len];
char str[len];
char cpy[2][len];
char word[27]="abcdefghijklmnopqrstuvwxyz";
cout<<"輸入檔位置:";
gets(fpath);
fptr=fopen(fpath,"r");//指到檔案所在地
if(fptr==NULL)
{
cout<<"開檔失敗"<<endl;
exit(0);
}
i=0;
while(fgets(str,len,fptr)!=NULL)
{
strcpy(cpy[i],str);
i++;
}
for(i=0;i<2;i++)
{
cout<<cpy[i];
}
cout<<endl;
n=0;
while(n<26)
{
count=0;
for(i=0;i<2;i++)
{
for(j=0;j<strlen(cpy[i]);j++)
{
if(cpy[i][j]==word[n])
{
count++;
}
}
}
cout<<word[n]<<"有"<<count<<"個"<<endl;
n++;
}
return 0;
}

創作回應

更多創作