# 一个小问题求指教

Hhcz_2419948234 2017-11-22 09:58:30
#include <stdio.h>
#include <stdlib.h>

#define OK 1
#define TRUE 1
#define ERROR 0
#define FALSE 0
#define OVERFLOW -1

typedef int Status;

typedef struct OLNode { /* struct of Node */
int i,j;
int e;
struct OLNode *right,*down;

typedef struct { /* struct of CrossList */
int mu,nu,tu; /* the number of row,col and non-zero number */
} CrossList;

Status CreateSMatrix_OL(CrossList *M);
Status PrintSMatrix_OL(CrossList M);

Status CreateSMatrix_OL(CrossList *M) /* Create the CrossList M */
{
int m,n,t,i,j,e,k;
OLNode *p,*q;

if(M) free(M);
scanf("%d,%d,%d",&m,&n,&t); /* input the M's row,col and non-zero's number */

M->mu=m;
M->nu=n;
M->tu=t;

exit(OVERFLOW);

exit(OVERFLOW);

for(k=0;k<m+1;k++) /* init the pointer to null */
for(k=0;k<n+1;k++)

for(scanf("%d,%d,%d",&i,&j,&e);i!=0;scanf("%d,%d,%d",&i,&j,&e)) 这个for无法跳出，查了很多次了，求解
{ /* input the non-zero's info */
p=(OLNode*)malloc(sizeof(OLNode));

if(!p) exit(OVERFLOW);

p->i=i;
p->j=j;
p->e=e;
p->right=NULL;
p->down=NULL; /* create the Node */

{
}
else
{ /* find the row position to insert */
p->right=q->right;
q->right=p;
} /* finish the insert */

{
}
else
{ /* find the col position to insert*/
p->down=q->down;
q->down=p;
} /* finish insert */
}

return OK;
} /* CreatrSMatrix_OL */

Status PrintSMatrix_OL(CrossList M) /* Print the non-zero information */
{
int i;
OLNode *p;
/* output the elem */
printf(" i j e ");
printf("---------");
for(i=1;i<=M.mu;i++)
{
if(!p)
{
p=p->right;
printf("\n %2d %2d %2d ",p->i,p->j,p->e);
}
}
return OK;
}/* PrintSMatrix */

int main (void)
{
CrossList M;
clrscr();

CreateSMatrix_OL(&M);
PrintSMatrix_OL(M);

return 0;
}
...全文
118 9 1 打赏 收藏 举报

9 条回复

paschen 2017-11-23

• 打赏
• 举报

• 打赏
• 举报

free是对应malloc/realloc/calloc的，除这三个申请的堆上空间，其他方式申请的，不能调用free； 还有问题：
``````//M->rhead=(OLink*)malloc(sizeof(OLNode)*(m+1));
exit(OVERFLOW);

exit(OVERFLOW);``````

• 打赏
• 举报

``````for (A;B;C) D;
//等价于
{
A;
while (1) {
if (!(B)) break;
D;
C;
}
}
``````

• 打赏
• 举报

Hhcz_2419948234 2017-11-23

• 打赏
• 举报

• 打赏
• 举报

Hhcz_2419948234 2017-11-23

• 打赏
• 举报

qq_41146587 2017-11-22

• 打赏
• 举报

Hhcz_2419948234 2017-11-22

• 打赏
• 举报

C语言

6.5w+

C语言相关问题讨论

2017-11-22 09:58