【发布时间】:2017-08-01 18:35:54
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int info;
struct node* next;
}Node;
typedef Node* list;
void printlist(list n)
{
while(n!=NULL)
{
printf("%d ",n->info);
n=n->next;
}
}
int main()
{
printf("Hello world!\n");
list head,temp;
char ch;
head=NULL;
printf("Want to add data:\n");
scanf("%c",&ch);
while(ch=='y'||ch=='Y')
{
temp=(list)malloc(sizeof(Node));
scanf("%d",&temp->info);
temp->next=head;
head=temp->next;
printf("Want to add more data:\n");
scanf("%c",&ch);
}
printlist(head);
return 0;
}
这是我的代码。 我的问题在这里,我不能和我的列表中的数据,但添加了节点...... 我认为我的“scanf”功能有问题.... 请帮我解决这个问题并将更正的代码发给我
thank u...hope I can get a reply soon
【问题讨论】:
-
head=temp->next;-->head=temp; -
你需要改变scanf("%c",&ch);到 scanf("%c",&ch);在这两个地方。
标签: c singly-linked-list insert-update