如果我运行这个程序,即使我将输入设为0,它还是计算得到它的值?

Bal*_*ick -2 c

#include<stdio.h>
#include<conio.h>
#include<malloc.h>

void main()
{
    struct node
    {
        int data;
        struct node *next;
    };
    struct node *head,*temp;
    int x;
    clrscr();
    head=(struct node *) malloc (sizeof(struct node));
    temp=head;
    while(temp!=NULL)
    {
        scanf("%d",x);
        temp->data=x;
        if(x==0)
        {temp->next=NULL;}
        else
        {temp->next=(struct node *) malloc (sizeof(struct node));}
        temp=temp->next;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在编写一个简单的链接列表程序的代码...我可以成功运行该程序但是当我按0时程序没有停止..

phy*_*us9 5

首先,你的scanf是错误的.它需要通过引用传递:

scanf("%d", &x);
Run Code Online (Sandbox Code Playgroud)

其次,在扫描之前你应该将x设置为0之外的其他值,以防万一.它的编写方式,循环中没有退出条件.

如果你想直接进入它,你可以尝试使用gdb并逐行踩它.

希望这可以帮助