C语言教程:简单的鼠标绘图程序
文章类别:
C语言程序设计 | 发表日期:2010-10-30 9:42:15
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct S{ int i;
int j;
int v;
struct S *next;
};
struct S *B,*p,*q;
main()
{ int k,row,col,c,m,n;
c=m=n=0;
clrscr();
printf("-----------Welcome to use!-------------\n\n");
B=(struct S *)malloc(sizeof(struct S));
printf("\nhow many rows do you want:");
scanf("%d",&row);
printf("\nhow many cols do you want:");
scanf("%d",&col);
p=(struct S *)malloc(sizeof(struct S));
B->i=row;
B->j=col;
B->next=p;
p->next=NULL;
printf("Input the JuZhen you want to deal:\n");
while(1)
{ scanf("%d",&k);
if(k!=0){ p->i=m;
p->j=n;
p->v=k;
q=(struct S *)malloc(sizeof(struct S));
q->next=NULL;
p->next=q;
p=q;
c++;
}
if(n<col-1) n=n+1;
else { m=m+1;
n=0;
}
if(m==row) break;
}
B->v=c;
printf("the B is:\n");
q=B;
while(q) { printf(" %d %d %d\n",q->i,q->j,q->v);
q=q->next;
}
getch();
}
只需要把
while(q)改成while(q->next)就行了。
程序结构很奇特