我在这里创建了一个TurboC++ C程序。这个简单的程序目标是创建一个链表,在列表的末尾插入每个元素,然后打印节点的值。(编辑该程序有所改变,使我更容易理解,但仍然是问题节点不是priniting存在) 的问题是,一些节点元素不是从错误的元素打印节点元素不打印在单链表列表中
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<ctype.h>
#include<conio.h>
struct node
{
int data;
struct node *link;
};
typedef struct node ND;
void main()
{
ND *start,*current,*temp;
start=NULL;
do
{
temp=(ND*)malloc(sizeof(ND));
printf("\n Enter Node Value");
scanf(" %d",&temp->data);
temp->link=NULL;
if(start==NULL)
{
start=current=temp;
}
else
{
current->link=temp;
current=temp;
}
fflush(stdin);
printf("\nDo You Want TO Continue?(Y/N)");
}while(toupper(getchar())!='N');
current=start;
printf("\nThe Elements OF Linked List ARE:");
while(current!=NULL)
{
printf(" %d",current->data);
current=current->link;
}
}
即使[多十年之久的Turbo C++控制台IDE](http://stackoverflow.com/questions/1961828/why-not-to-use-turbo-c)有一个集成的调试器。你应该用它来追踪问题出在哪里。不相关的是,你在包含列表中缺少'ctype.h'和'stdlib.h',这两者都应该分别包含在'toupper'和'malloc'支持中。 – WhozCraig
寻求调试帮助的问题(“为什么这个代码不工作?”)必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无益。请参阅:[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。简而言之,这不是“免费调试我的代码”服务。 –
我写了上面最短的代码,我已经说明了我的问题,列表中的节点元素不打印... – Mihir