题目描述:
文件中按文本方式存放了一段其他文章,其中有若干长度小于15的英文单词,单词之间用空格分开,无其他符号。顺序读取这段文章的不同的单词(大小写敏感),同时在读取的过程中排除所有的单词THE以及变形,即这些单词不能出现在读取的结果中。将读取的所有单词的首字母转大写后,输出到文件中,每个单词一行。
输入描述:
The constructor is used to initialize the object The destructor is used to delete the Object the calling sequence of constructor is opposite to the calling sequence of destructor
输出描述:
Constructor
Is
Used
To
Initialize
Object
Destructor
Delete
Object
Calling
Sequence
Of
Opposite
代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
char word[100][15];
char store[15];
FILE *fp,*fa;
int i=0,j=0,s=0;
int res=-1;
if((fp=fopen("D:\\2019Post\\pat\\pat\\data2008.txt","r"))==NULL){
printf("can not open the file");
exit(0);
}
while(!feof(fp)){
fscanf(fp,"%s",word[i]);
i++;
}
if((fa=fopen("D:\\2019Post\\pat\\pat\\data2008_out.txt","w"))==NULL){
printf("can not open the file");
exit(0);
}
for(j=0;j<i;j++){
strcpy(store,word[j]);//很重要,不然的话会改掉data中的数据,以至于结果中出现重复。
if(strcmp("The",store)!=0&&strcmp("the",store)!=0){
res=1;
for(s=0;s<j;s++){
if(strcmp(word[s],store)==0)
res=0;
}
}
if(res==1){
if(store[0]>='a'&&store[0]<='z'){
store[0]-=32;
}
fprintf(fa,"%s\n",store);
res=-1;
}
}
fclose(fp);
fclose(fa);
}