本帖最后由 zhuochengliu 于 2014-10-5 21:48 编辑
各位:
请问我用c语言编个程序是将in.txt文件中的二维数组进行计算,将计算结果输出到文件out.dat中,in.txt文件中的数据格式为1 2 3 4 其中行向量分别代表a,b,c,d;计算公式为:k=a+b+c+d;
3 4 5 6
将计算结果的k值按行向量输出到文件out.dat中;
以下是我的程序源文件:
# include<stdio.h> main() { FILE *in,*out; char ch,infile[10],outfile[10]; int i; float a,b,c,d,k; printf("Enter the infile name:\n"); scanf("%s",infile); printf("Enter the outfile name:\n"); scanf("%s",outfile); if(( in=fopen(infile,"r"))==NULL) {printf("cannot open infile\n"); exit(0); } if((out=fopen(outfile,"w"))==NULL) {printf("cannot open outfile name:\n"); exit(0); } for(i=0;i<2;i++) {fscanf(in,"%1f","%1f","%1f","%1f",&a,&b,&c,&d); k=a+b+c+d; fprintf(out,"%1f",k); } fclose(in); fclose(out); } 编译可以通过,但执行zhen.exe文件时出现“zhen.exe停止工作”信息,请指教。
|