如果我运行这个程序,即使我将输入值设为0,它也会继续获取其中的值吗? #包括 #包括 #包括 void main() { 结构节点 { int数据; 结构节点*下一步; }; 结构节点*head,*temp; int x; clrsc(); head=(结构节点*)malloc(sizeof(结构节点)); 温度=水头; while(temp!=NULL) { scanf(“%d”,x); 温度->数据=x; 如果(x==0) {temp->next=NULL;} 其他的 {temp->next=(结构节点*)malloc(sizeof(结构节点));} 温度=温度->下一步; } }
我正在为一个简单的链接列表程序编写代码。。。我可以成功运行程序,但当我按0时,程序不会停止。首先,您的扫描错误。它需要通过引用传递:如果我运行这个程序,即使我将输入值设为0,它也会继续获取其中的值吗? #包括 #包括 #包括 void main() { 结构节点 { int数据; 结构节点*下一步; }; 结构节点*head,*temp; int x; clrsc(); head=(结构节点*)malloc(sizeof(结构节点)); 温度=水头; while(temp!=NULL) { scanf(“%d”,x); 温度->数据=x; 如果(x==0) {temp->next=NULL;} 其他的 {temp->next=(结构节点*)malloc(sizeof(结构节点));} 温度=温度->下一步; } },c,C,我正在为一个简单的链接列表程序编写代码。。。我可以成功运行程序,但当我按0时,程序不会停止。首先,您的扫描错误。它需要通过引用传递: #include<stdio.h> #include<conio.h> #include<malloc.h> void main() { struct node { int data; struct node *next; }; struct node *head
#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;
}
}
其次,为了以防万一,在扫描x之前,应该将x设置为0以外的值。按照编写方式,循环中没有退出条件
如果您想直接进入gdb,可以尝试使用gdb并逐行执行
希望这对您有所帮助您知道如何使用调试器吗?请告诉我们是哪本书或教程告诉您使用
void main()
?它的作者对C不太了解。正确的定义是intmain(void)
。正确的术语是“将指针传递给x”。
scanf("%d", &x);