新手上路问题 我的程序要弄好多文件 我想简化下 但是不清楚该怎么弄
程序代码:
#include "stdafx.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <process.h> int main(int argc,char *argv[]) { char ch; char a[1024]; char b[1024]; FILE *fp1,*fp2,*fp3,*fp4; if((fp1=fopen(argv[1],"r+"))==NULL) { printf("file1 error!\n"); exit(1); } if((fp2=fopen(argv[2],"w+"))==NULL) { printf("file2 error!\n"); exit(2); } if((fp3=fopen(argv[3],"w+"))==NULL) { printf("file3 error!\n"); exit(3); } if((fp4=fopen(argv[4],"w+"))==NULL) { printf("file4 error!\n"); exit(4); } while(!feof(fp1)) if(fgets(a,1000,fp1)) { if(fgetc(fp1)=='T') { if(fgetc(fp1)=='i') { if(fgetc(fp1)=='m') { if(fgetc(fp1)=='e') { fscanf(fp1,"%*[^\n]%*c"); while((ch=fgetc(fp1))!=EOF) fputc(ch,fp2); rewind(fp2); while(!feof(fp2)) if(fgets(a,1000,fp2)) { sscanf(a,"%[^E] ",b); fputs(b,fp3); fputc('\n',fp3); } rewind(fp3); while(!feof(fp3)) if(fgetc(fp3)=='\t') { fseek(fp3,0,1); fgets(a,1000,fp3); fputs(a,fp4); } } } } } } fclose(fp1); fclose(fp2); fclose(fp3); fclose(fp4); }
[ 本帖最后由 zxlwinner 于 2011-8-2 17:08 编辑 ]