写了程序出错了,可是不知道错在哪里
#include <stdio.h>#include <stdlib.h>
void operation(FILE* ifp,FILE* ofp)
{
float a, b;
const int LOOPLIMIT =10000;
if ( (ifp==NULL) || (ofp==NULL) ){
fprintf(stderr,"[Error] null filr pointer detected.\n");
exit(-1);
}
for (int i=0; i<LOOPLIMIT; i++) {
if (fscanf(ifp,"%f%f",&a,&b) == EOF)
break;
float c = a *b;
fprintf(ofp, "%g, %g, %g\n",a,b,c);
}
}
int main(int argc, char* argv[])
{
FILE* ifp = NULL;
FILE* ofp = NULL;
char* ifile = NULL;
char* ofile = NULL;
if(argc!=3) {
fprintf(stderr,"usage: %s inputfile outputfile\n", argv[0]);
exit(1);
}
ifile =argv[1];
ofile =argv[2];
if( (ifp = fopen(ifile,"rt"))==NULL) {
fprintf(stderr,"can not open file %S\a\n", ifile);
exit(2);
}
if( (ifp = fopen(ifile,"wt"))==NULL) {
fprintf(stderr,"can not open file %S\a\n", ifile);
exit(3);
}
operation(ifp,ofp);
fclose(ofp);
fclose(ifp);
return(0);
}