怎么输出“+”号?高手帮忙改一下
#include "stdio.h"#include "conio.h"
#include"graphics.h"
#include"math.h"
#include"stdlib.h"
#define M 100
struct
{
int a[M][2];
int n;
int G0[M];
char argv[1024];
} data1;
int x0,y0,Xm,Ym,dx,dy;
main()
{
char buf[1024];
int grahpdriver=DETECT, grahpmode, i;
printf("Please Input The Way:Such As “F:/b.txt“");
scanf("%s",data1.argv);
sprintf(buf,"edit %s",data1.argv);
system(buf);
mycount();
getch();
myread();
getch();
myread1();
getch();
initgraph(&grahpdriver, &grahpmode, "");
x0=0,y0=0;
for(i=0; i<data1.n; i++)
{
switch(data1.G0[i])
{
case 0:
G00(data1.a[i][0],data1.a[i][1]);
break;
case 1:
G01(data1.a[i][0],data1.a[i][1]);
break;
default:
printf("command unknow error\n");
system("pause");
exit(0);
break;
}
}
free(data1.G0);
free(data1.a);
getch();
}
int G00(int x,int y)
{
float xt,yt,l,i,n;
xt=x-x0;
yt=y-y0;
l=sqrt(xt*xt+yt*yt);
n=l/5;
if(l)xt=5*xt/l;
else xt=0;
if(l)yt=5*yt/l;
else yt=0;
getch();
setcolor(GREEN);
for(i=0; i<n; i++)
putpixel(x0+i*xt,y0+i*yt,2);
x0=x,y0=y;
}
int G01(int x,int y)
{
float Xi=x0,Yi=y0;
float Xm=x,Ym=y,l,xt,yt,i;
xt=Xm-Xi;
yt=Ym-Yi;
l=sqrt(xt*xt+yt*yt);
if(l)xt=1*xt/l,yt=1*yt/l;
else xt=0,yt=0;
getch();
moveto(x0,y0);
setcolor(GREEN);
lineto(x,y);
x0=x,y0=y;
getch();
moveto(Xi,Yi);
for(i=0; i<l; i++)
{
putpixel(Xi+i*xt,Yi+i*yt,1);
delay(5000);
}
printf("+");
}
int mycount()
{
FILE * FP=NULL;
char ch;
int count=0;
int white=1;
FP= fopen(data1.argv, "r");
if(FP==NULL)
{
printf("Can not open the file.\n");
getch();
exit(0);
}
while((ch=fgetc(FP))!=EOF)
switch(ch)
{
case' ':
case'\t':
case'\n':
white++;
break;
default :
if(white)
{
white=0;
count++;
}
}
fclose(FP);
data1.n=count/3;
}
int myread()
{
int j=0;
FILE *FP=NULL;
char string [81];
FP= fopen(data1.argv, "r");
if(FP==NULL)
{
printf("Can not open the file.\n");
getch();
exit(0);
}
myread1();
for(j=0; j<data1.n; j++)
{
if(3!=fscanf(FP," G0%d x%d y%d;",
&data1.G0[j],
&data1.a[j][0],
&data1.a[j][1]))break;
}
while(fgets(string,81,FP))
printf("%s",string);
fclose(FP);
printf("\ncommand readed:\n");
for(j=0; j<data1.n; j++)
printf("G0%d x%d y%d;\n",data1.G0[j],data1.a[j][0],data1.a[j][1]);
getch();
return 0;
}
int myread1()
{ FILE *FP=NULL;
FP= fopen("C:/Win-TC/a.txt", "r");
if(FP==NULL)
{ printf("Can not open the file.\n");getch();exit(0);}
fscanf(FP,"%d", &data1.n);
fclose(FP);
return 0;
}
这是我编写的直线插补程序,程序运行结果正常,现在要求在输出的实线上打上“+”号,如何实现?
假如文本文件内容为:
G00 x100 y200;
G01 x326 y326;
G01 x153 y198;
G00 x400 y398;
G01 x350 y256;
G01 x200 y175;
[ 本帖最后由 naturelop 于 2011-6-14 20:51 编辑 ]