Tvally 2022-09-24 19:03 采纳率: 61.1%
浏览 944

C语言未定义标识符及各种错误

问题遇到的现象和发生背景

VS2022下编译不通过,NULL显示的是未定义标识符,已经定义的结构体显示的是未定义标识符,各种错误都有

用代码块功能插入代码,请勿粘贴截图
#include <stdio.h>
#include <stdlib.h>


struct Node
{
    int data;
    struct Node* next; // C++中只需要写Node*
};
struct Node* head;
void Insert(int x)
{
    struct Node* temp = (Node*)malloc(sizeof(struct Node));
    temp->data = x;
    temp->next = head;
    head = temp;
}
void Print()
{
    struct Node* temp = head;
    printf("List is:");
    while (temp != NULL)
    {
        printf(" %d", temp->next);
        temp = temp->next;
    }
    printf("\n");
}
int main(void)
{
    int n, x;
    head = NULL;
    printf("How many numbers?\n");
    
    scanf("%d\n", &n);
    for (int i = 0; i < n; i++)
    {
        printf("Enter the number:\n");
        scanf("%d", &x);
        Insert(x);
        Print(x);
    }

    return 0;
}

运行结果及报错内容

img

  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-24 21:02
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 9月24日