main函数中用了命令行参数 data1.txt data2.txt data3.txt
#include <stdio.h>
#include <stdlib.h>
//////////////////////////////////////////////////////////////////////////
int process(char* infile1,char* infile2,char* outfile);
// return 0: if everything is ok
// 1: if something is wrong, such as error opening a file
//////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
if (argc<4) { printf("command argument error\n"); system("pause"); exit(1); }
//////////////////////////////////////////////////////////////////////////
if (process(argv[1],argv[2],argv[3])) // argv[1] and argv[2] are input filenames
// argv[3] is output filename
//////////////////////////////////////////////////////////////////////////
{ printf("file processing error\n"); system("pause"); exit(1); }
printf("\n\nDone!\nPlease open file \"%s\" to check.\n",argv[3]);
system("pause"); return 0;
}
///////////////////////////////////////////////////////以上是老师给的主程序,下面是我编的。
#include <stdio.h>
#include <stdlib.h>
int process(char* infile1,char* infile2,char* outfile)
{
FILE *fp1,*fp2,*fp3;int a[200],i,j,k,l,temp,b;
if((fp1=fopen(infile1,"r"))==NULL)
{
printf("can't open the file!\n");
exit(1);
}
if((fp2=fopen(infile2,"r"))==NULL)
{
printf("can't open the file!\n");
exit(1);
}
if((fp3=fopen(outfile,"w"))==NULL)
{
printf("can't open the file!\n");
exit(1);
} //至此打开三个文档
i=0;
while(!feof(fp1))
{
fscanf(fp1,"%d",&a[i]);
i++;
}
while(!feof(fp2))
{
fscanf(fp2,"%d",&a[i]);
i++;
} //将前两个文档的数字放入数组a中
for(k=0;k<i;k++)
{
j=k;
for(l=k+1;l<i;l++)
{
if(a[j]>a[l]){j=l;}
}
if(j!=k)
{temp=a[j];a[j]=a[k];a[k]=temp;}
} //排序
for(j=0;j<i;j++)
{
fprintf(fp3,"%d",a[j]);
} //将排序后的放入另一文档
}
求助错在哪了。。。。谢谢了。