malloc函数申请内存失败、?
#include <stdio.h>#include <stdlib.h>
typedef struct OLNode
{
int row,col;
int vaule;
struct OLNode * right, * down;
}OLNode,*OLink;
typedef struct
{
OLink * row_head,* col_head;
int m,n,len;
}CrossList;
void CreateCrossList(CrossList *M)
{
int m,n,t,k;
int i,j,e;
OLink p,q;
printf("请输入行的个数m,列的个数n,数据元素的总个数t:\n");
scanf("%d%d%d",&m,&n,&t);
M->m=m;
M->n=n;
M->len=t;
if(!(M->row_head=(OLink*)malloc((m+1)*sizeof(OLink))));
{
printf("申请行失败!\n");
exit(0);
}
if(!(M->row_head=(OLink*)malloc((n+1)*sizeof(OLink))));
{
printf("申请列失败!\n");
exit(0);
}
for(k=1;k<m+1;k++)
M->row_head[k]=NULL;
for(k=1;k<n+1;k++)
M->col_head[k]=NULL;
printf("请输入元素的行下标,列下标,值:\n");
for(scanf("%d%d%d",&i,&j,&e);i!=0;scanf("%d%d%d",&i,&j,&e))
{
if(!(p=(OLNode*)malloc(sizeof(OLNode))));
exit(0);
p->row=i;
p->col=j;
p->vaule=e;
if(M->row_head[i]==NULL)
M->row_head[i]=p;
else
{
q=M->row_head[i];
while(q->right!=NULL&&q->right->col<j)
q=q->right;
p->right=q->right;
q->right=p;
}
if(M->col_head[i]==NULL)
M->col_head[j]=p;
else
{
q=M->col_head[j];
while(q->down!=NULL&&q->down->col<i)
q=q->down;
p->down=q->down;
q->down=p;
}
}
}
int main()
{
CrossList M;
CreateCrossList(&M);
return 0;
}
我感觉代码没有访问越界