请各位高手指点迷津?

xyy1983 2004-08-03 11:38:21
以下程序在TC下运行后输入所需点后为何不能连线?
#include "graphics.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#include "mem.h"
#include "ctype.h"
#include "alloc.h"
typedef struct D1
{ int sum;
struct D1 *next;
}STUSUM;


int i,j,m=0,n,h;
int a[20];
int arw1[10]={10,40,5,40,10,32,15,40,10,40 };
int arw2[10]={618,465,618,460,626,465,618,470,618,465};

STUSUM *init();
STUSUM *create();
void getsum(STUSUM *h);
int DrawZB();

STUSUM *init()
{
return NULL;
}

STUSUM *create()
{ int i;
STUSUM *h=NULL,*info;
for(i=1;i<=5;i++)
{
info=(STUSUM *)malloc(sizeof(STUSUM));
if(!info)
{
printf("\nout of memory");
return NULL;
}
start: printf("Please Input The %d Sud sum\n",i);
scanf("%d",&info->sum);
if(info->sum==0)
goto start;
info->next=h;
h=info;
}
return(h); /*返回头指针*/
}

/*输出链表中结点信息*/
void getsum(STUSUM *h)
{
STUSUM *p; /*移动指针*/
clrscr(); /*清屏*/
p=h; /*初值为头指针*/
while(p!=NULL)
{ p->sum=&a[m];
p=p->next;
m++;
}
}

void main()
{int gd=DETECT,gr;
STUSUM *head;
head=init();
head=create();
getsum(head);
initgraph(&gd,&gr,"c:\\turboc2");
setbkcolor(8);
cleardevice();
DrawZB();
getch();
closegraph();
}

int DrawZB()
{int static p=20;
int static l=2;
line(10,465,618,465);
line(10,40,10,465);
drawpoly(5, arw1);
drawpoly(5, arw2);
for(i=10;i<=618;i+=20)
line(i,460,i,463);
for(i=465;i>=40;i-=20)
line(10,i,13,i);
for(h=0;h<5;h++)
{
line(p,a[l-2],p+20,a[l-1]);
p+=20;
line(p,a[l-1],p+20,a[l]);
p+=20;
l+=2;
}
return 0;
}

...全文
78 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
geochway 2004-08-03
  • 打赏
  • 举报
回复
p->sum=&a[m]; 这一句似乎有问题吧?
是不是应改成 p->sum=a[m];

你最好把程序的功能目的说清楚,要不然谁
知道你的程序想干啥呀?




xyy1983 2004-08-03
  • 打赏
  • 举报
回复
谢谢楼上的提示,此程序首先用链表存储数值"creat()",然后将数值由"getsum()"放如一维数组a[20],再通过"DrawZB()"画出坐标图;

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧