(求帮助)谁能帮本人看一下这段代码哪里出问题了,运行不了

C语言 码拜 8年前 (2016-04-25) 783次浏览
#include”stdio.h”
#include”math.h”
FILE*fp;
int i,gcode;
char fname[14],gvalue[65];
float xs[100],ys[100],zs[100],xe[100],ye[100],ze[100];
main()
{int n;
i=0;
scanline();
printf(“Enter data file name:”);
scanf(“%s”,fname);
fp=fopen(fname,”w”);
fprintf(fp,”%d\n”,i);
for(n=1;n<=i;n++)
{fprintf(fp,”%f,%f,%f\n”,xs[n],ys[n],zs[n]);
fprintf(fp,”%f,%f,%f\n”,xe[n],ye[n],ze[n]);
}
fclose(fp);
}
int scanline()
{printf(“Enter DXF file name:”);
scanf(“%s”,fname);
strcat(fname,”.dxf”);
fp=fopen(fname,”r”);
do{fscanf(fp,”%d”,&gcode);
fscanf(fp,”%s”,gvalue);
}while(gcode!=2||strcmp(gvalue,”ENTITIES”)!=0);
do{fscanf(fp,”%d”,&gcode);
fscanf(fp,”%s”,gvalue);
if(gcode==0&&strcmp(gvalue,”LINE”)==0)outline();
}while(gcode!=0||strcmp(gvalue,”ENDSEC”)!=0);
fclose(fp);
return0;
}
int outline()
{do{fscanf(fp,”%d”,&gcode);
if(gcode==10)
{i=i+1;
fscanf(fp,”%f”,&xs[i]);
}
else
fscanf(fp,”%s”,gvalue);
}while(gcode!=10);
fscanf(fp,”%d”,&gcode);
fscanf(fp,”%f”,&ys[i]);
fscanf(fp,”%d”,&gcode);
fscanf(fp,”%f”,&zs[i]);
fscanf(fp,”%d”,&gcode);
fscanf(fp,”%f”,&xe[i]);
fscanf(fp,”%d”,&gcode);
fscanf(fp,”%f”,&ye[i]);
fscanf(fp,”%d”,&gcode);
fscanf(fp,”%f”,&ze[i]);
return0;
}
解决方案

80

函数要先声明才行

#include"stdio.h"
#include"math.h"
#include"string.h"
FILE*fp;
int i,gcode;
char fname[14],gvalue[65];
float xs[100],ys[100],zs[100],xe[100],ye[100],ze[100];
int scanline();
int outline();
void main()
{
	int n;
	i=0;
	scanline();
	printf("Enter data file name:");
	scanf("%s",fname);
	fp=fopen(fname,"w");
	fprintf(fp,"%d\n",i);
	for(n=1;n<=i;n++)
	{fprintf(fp,"%f,%f,%f\n",xs[n],ys[n],zs[n]);
	fprintf(fp,"%f,%f,%f\n",xe[n],ye[n],ze[n]);
	}
	fclose(fp);
}
int scanline()
{
	printf("Enter DXF file name:");
	scanf("%s",fname);
	strcat(fname,".dxf");
	fp=fopen(fname,"r");
	do{fscanf(fp,"%d",&gcode);
	fscanf(fp,"%s",gvalue);
	}while(gcode!=2||strcmp(gvalue,"ENTITIES")!=0);
	do{fscanf(fp,"%d",&gcode);
	fscanf(fp,"%s",gvalue);
	if(gcode==0&&strcmp(gvalue,"LINE")==0)outline();
	}while(gcode!=0||strcmp(gvalue,"ENDSEC")!=0);
	fclose(fp);
	return 0;
}
int outline()
{
	do{fscanf(fp,"%d",&gcode);
	if(gcode==10)
	{
		i=i+1;
		fscanf(fp,"%f",&xs[i]);
	}
	else
		fscanf(fp,"%s",gvalue);
	}while(gcode!=10);
	fscanf(fp,"%d",&gcode);
	fscanf(fp,"%f",&ys[i]);
	fscanf(fp,"%d",&gcode);
	fscanf(fp,"%f",&zs[i]);
	fscanf(fp,"%d",&gcode);
	fscanf(fp,"%f",&xe[i]);
	fscanf(fp,"%d",&gcode);
	fscanf(fp,"%f",&ye[i]);
	fscanf(fp,"%d",&gcode);
	fscanf(fp,"%f",&ze[i]);
	return 0;
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明(求帮助)谁能帮本人看一下这段代码哪里出问题了,运行不了
喜欢 (0)
[1034331897@qq.com]
分享 (0)