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

#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;
}
此题没有测试,所以不能说完全正确!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值