2011_1华中科技大学机试真题

来源:互联网 发布:一个c语言源程序是由 编辑:程序博客网 时间:2024/04/30 10:36
#include<stdio.h>#include<stdlib.h>int main(){FILE *fp,*fp1;char e;int flag,count1,count2,count3;if((fp=fopen("D:\\abc0.txt","w"))==NULL){printf("文件打开失败!\n");exit(1);}while((e=getchar())!=EOF)fputc(e,fp);fclose(fp);if((fp1=fopen("D:\\abc1.txt","w"))==NULL){printf("文件打开失败!\n");exit(1);}if((fp=fopen("D:\\abc0.txt","r"))==NULL){printf("文件打开失败!\n");exit(1);}flag=0;while((e=fgetc(fp))!=EOF){if(e==' '){if(flag==1) continue;fputc(e,fp1);printf("%c",e);flag=1;continue;}else{fputc(e,fp1);printf("%c",e);flag=0;continue;}}fclose(fp);fclose(fp1);if((fp1=fopen("D:\\abc1.txt","r"))==NULL){printf("文件操作失败!\n");exit(0);}count1=count2=count3=0;while((e=fgetc(fp1))!=EOF){count1++;if(e==' '||e==':'||e==':'||e=='\''||e=='\"'||e=='.'||e=='!'||e=='?')count2++;if(e=='.'||e=='!'||e=='?')count3++;}printf("\n%d\t%d\t%d\n",count1,count2,count3);fclose(fp1);system("pause");return 0;}
此题没有测试,所以不能说完全正确!
0 0
原创粉丝点击