结构列表中的内存错误(存储未知)
memory error in struct list (storage uknown)
我正在尝试编译此代码,但出现内存错误:list1.c:25:15: 错误:‘cnodo’ 的存储大小未知
结构 nobo cnodo;
谁能告诉我这个错误的根源是什么以及如何避免它?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct nodo {
int info;
struct nodo *prec;
struct nodo *succ;
} ;
typedef struct nodo nodo;
void stampa (struct nodo *p);
int main (void) {
struct nodo *p;
struct nodo anodo;
struct nodo bnodo;
struct nobo cnodo;
anodo.info = 99;
anodo.prec = NULL;
anodo.succ = NULL;
bnodo.info = 1010;
bnodo.prec = NULL;
bnodo.succ = NULL;
cnodo.info = 1020;
cnodo.prec = NULL;
cnodo.succ = NULL;
anodo.succ = &bnodo;
bnodo.prec = &anodo;
bnodo.succ = &cnodo;
cnodo.prec = &bnodo;
p = &anodo;
stampa(p);
return 0;
}
void stampa (struct nodo *p) {
while (p != NULL) {
printf("\n nodo value is : %d \n ", p -> info);
p = p -> succ;
}
}
因为
struct nodo cnodo;
没有
struct nobo cnodo;
/* ^ d not b
struct nobo cnodo;
应该是
struct nodo cnodo;
(打字错误)
你打错了。变化
struct nobo cnodo;
至
struct nodo cnodo;
我正在尝试编译此代码,但出现内存错误:list1.c:25:15: 错误:‘cnodo’ 的存储大小未知 结构 nobo cnodo;
谁能告诉我这个错误的根源是什么以及如何避免它?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct nodo {
int info;
struct nodo *prec;
struct nodo *succ;
} ;
typedef struct nodo nodo;
void stampa (struct nodo *p);
int main (void) {
struct nodo *p;
struct nodo anodo;
struct nodo bnodo;
struct nobo cnodo;
anodo.info = 99;
anodo.prec = NULL;
anodo.succ = NULL;
bnodo.info = 1010;
bnodo.prec = NULL;
bnodo.succ = NULL;
cnodo.info = 1020;
cnodo.prec = NULL;
cnodo.succ = NULL;
anodo.succ = &bnodo;
bnodo.prec = &anodo;
bnodo.succ = &cnodo;
cnodo.prec = &bnodo;
p = &anodo;
stampa(p);
return 0;
}
void stampa (struct nodo *p) {
while (p != NULL) {
printf("\n nodo value is : %d \n ", p -> info);
p = p -> succ;
}
}
因为
struct nodo cnodo;
没有
struct nobo cnodo;
/* ^ d not b
struct nobo cnodo;
应该是
struct nodo cnodo;
(打字错误)
你打错了。变化
struct nobo cnodo;
至
struct nodo cnodo;