二楼的说的对,附原代码:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp,*fp1,*fp2,*fp3;
char ch,i=0;
if((fp=fopen("test.txt","rt"))==NULL)
{
printf("Can't open file strike any key exit!");
getch();
exit(1);
}
if((fp1=fopen("test1.txt","wt"))==NULL)
{
printf("Can't create file strike any key exit!");
getch();
exit(1);
}
if((fp2=fopen("test2.txt","wt"))==NULL)
{
printf("Can't open file strike any key exit!");
getch();
exit(1);
}
if((fp3=fopen("test3.txt","wt"))==NULL)
{
printf("Can't open file strike any key exit!");
getch();
exit(1);
}
while((ch=fgetc(fp))!=EOF)
{
if(ch=='%') i++;
switch (i)
{
case 1:fputc(ch,fp1);break;
case 2:fputc(ch,fp2);break;
case 3:fputc(ch,fp3);break;
}
}
fclose(fp3);fclose(fp2);
fclose(fp1);fclose(fp);
return 0;
}