我有以下代码。
'list' undeclared (first use in this function)
时出现错误。
请帮助我
#include <stdio.h>
#include <stdlib.h>
struct list{
int data;
struct list *next;
};
typedef struct list *head;
int main()
{
struct list *start;
int i;
start = (list *) malloc(sizeof(struct list));
printf("\nEnter the data : \n");
scanf("%d", &i);
start->data = i;
start->next = NULL;
while(list->next != NULL)
{
printf("%d ", list->data);
list = list->next;
}
return 0;
}
最佳答案
您正在使用类型 list
而不是变量名 start
。正确的代码:
while (start->next != NULL)
{
start = start->next;
// etc.
}
关于c - 'list' 未声明(在此函数中首次使用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10332970/