【发布时间】:2012-05-07 03:49:15
【问题描述】:
我有以下代码。
我收到'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;
}
【问题讨论】:
-
你不必发布截图...
-
@ThiefMaster 比什么都不发好(没有代码,没有错误日志)..
-
评论: 1.不要投
malloc()的返回值; 2. 不要使用sizeof struct作为它的参数,而是使用sizeof(*start); 3. 为什么typedef struct list *head你从来不用它?
标签: c