C语言问题
求助:应该怎么改。报错:
```
main.c:38:12: error: array subscript is not an integer
38 | (*adjlist)->FirstNode=p;
| ^
main.c:42:21: error: array subscript is not an integer
42 | p->pNext=(*adjlist)->FirstNode;
| ^
main.c:43:12: error: array subscript is not an integer
43 | (*adjlist)->FirstNode=p;
| ^
```
```
# include<stdio.h>
# include<stdlib.h>
# define MaxVertex 1000
typedef struct AcrNode
{
int adjvex;
struct AcrNode *pNext;
int info;
}AcrNode,*pAcrNode;
typedef struct Vertex
{
int data;
AcrNode * FirstNode;
}Vertex,Adjlist;
void CreateVertexlist(Vertex*a)
{
int i,n,k,b,j;
Adjlist *adjlist=NULL;
AcrNode*p;
printf("输入总共有几个顶点几条边");
scanf("%d %d",&n,&k);
for(i=0;i<n;i++)
{
printf("输入第%d个节点的信息:",i);
scanf("%d",adjlist->data);
adjlist->FirstNode=NULL;
}
for(j=0;j<k;k++)
{
scanf("%d %d",&a,&b);
p=(AcrNode*)malloc(sizeof(AcrNode));
p->adjvex=b;
/*p->pNext=(*adjlist)->FirstNode;*/
(*adjlist)->FirstNode=p;
p=(AcrNode*)malloc(sizeof(AcrNode));
p->adjvex=b;
p->pNext=(*adjlist)->FirstNode;
(*adjlist)->FirstNode=p;
}
}
``` 类型不匹配,a是Vertex*型,数组下标要求int 函数声明处:void CreateVertexlist(Vertex*a),a是Vertex*,在scanf()里被按照整形输入,这一步就有问题了,后边还把a当作整形来用。 像这一行一样,去掉*。 adjlist->FirstNode=NULL; 这是c++吧 类型不匹配
页:
[1]