c - 'list' 未声明(在此函数中首次使用)

标签 c

我有以下代码。 '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/

相关文章:

c++ - 从 C 到 C++ : function was not declared in this scope

c - 为什么大小为 '0' 的 realloc 允许多次释放指针,但大小为 '0' 的 malloc 不允许?

c - 无法理解为什么释放内存会引发错误

c - 存储仅检索一次然后删除的元素的最佳数据结构是什么?

c++ - 如何使用 POSIX select()

c - 使用信号处理程序暂停/恢复子进程

c - 如何在 GTK 中制作无限循环

c - 如何使用 libgit2 通过 ssh 推送 git 存储库

c - 使用 (int) sqrt(N) 导致 'array bound is not an integer constant'

c - 需要解释奇数 for 循环/作用域问题