在C中将指针设置为NULL,而不是编译

在C中将指针设置为NULL,而不是编译,c,pointers,null,C,Pointers,Null,由于某种原因,当我试图编译我的代码.exe文件只是在它完成后消失。。。没有任何错误或警告 这就是我的代码的样子: #include <stdio.h> #include <stdlib.h> typedef struct student_ { int matnum; char vorname[20]; struct student_ *next; } student; int main (int argc, char **argv) {

由于某种原因,当我试图编译我的代码.exe文件只是在它完成后消失。。。没有任何错误或警告

这就是我的代码的样子:

#include <stdio.h>
#include <stdlib.h>

typedef struct student_ 
{
    int matnum;
    char vorname[20];
    struct student_ *next;
} student;

int main (int argc, char **argv) 
{
    student hans;
    hans.matnum = 12;

    student peter;
    peter.matnum = 13;
    peter.next = NULL; // THIS PART CAUSES MY PROBLEM

    hans.next = &peter;

    student *curr = &hans;
    while(curr != NULL)
    {
        printf("matnum: %d\n", (*curr).matnum);
        curr = curr->next;
    }

    return 0; 
}
这就是我想要达到的目标,但它不起作用\


从评论中:


我没有错。在我输入“gcc-Wall-o test test.c”之后,test.exe会在那里停留一秒钟,然后被删除


对此最合理的解释是,您的防病毒软件正在删除可执行文件。您的程序在这里编译并运行良好

无论出于何种原因,可疑代码行都会生成反病毒软件与已知病毒匹配的编译代码。当您删除该行时,它不再与病毒匹配,但程序当然会失败


暂时禁用杀毒软件以确认这一假设。

这没有任何意义;它要么编译,要么不编译,您会收到错误消息。是编译错误,还是运行时错误?你能复制错误文本并粘贴到你的问题中吗?我没有收到错误。在我输入“gcc-Wall-o test test.c”后,test.exe会在那里停留一秒钟,然后被删除。删除可疑代码行时它会保留吗?是的。但随后程序崩溃了,这是有道理的,因为指针curr被设置为非学生。天哪,我关掉了avast,它现在可以工作了!多谢各位@大卫+1这是开箱即用的
peter.next = NULL; // THIS PART CAUSES MY PROBLEM