我正在尝试编译此代码,但我收到内存错误:list1.c:25:15:错误:'cnodo'的存储大小未知 struct 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;
}
}
答案 0 :(得分:1)
因为它是
struct nodo cnodo;
不
struct nobo cnodo;
/* ^ d not b
答案 1 :(得分:0)
你有一个错字。变化
struct nobo cnodo;
到
struct nodo cnodo;