C 为什么可以';我不能在我的链接列表中输入多个条目吗?

C 为什么可以';我不能在我的链接列表中输入多个条目吗?,c,data-structures,linked-list,C,Data Structures,Linked List,我是C语言的新手,我正在尝试学习链表,但由于某些原因,我不能给出一个以上的值。程序在给出一个值后结束。 这是我的密码: #include<stdio.h> #include<stdlib.h> typedef struct node_type { int data; struct node_type *next; } node; int main() { typedef node *list; list head, temp; c

我是C语言的新手,我正在尝试学习链表,但由于某些原因,我不能给出一个以上的值。程序在给出一个值后结束。 这是我的密码:

#include<stdio.h>
#include<stdlib.h>
typedef struct node_type {
    int data;
    struct node_type *next;
} node;

int main()
{
    typedef node *list;
    list head, temp;
    char ch;
    int n;
    head = NULL;
    printf("enter Data?(y/n)\n");
    scanf("%c", &ch);

    while ( ch == 'y' || ch == 'Y')
    {
        printf("\nenter data:");
        scanf("%d", &n);
        temp = (list)malloc(sizeof(node));
        temp->data = n;
        temp->next = head;
        head = temp;
        printf("enter more data?(y/n)\n");

        scanf("%c", &ch);

    }
    temp = head;
    while (temp != NULL)
    {
        printf("%d", temp->data);
        temp = temp->next;
    }

    return 0;
}
#包括
#包括
类型定义结构节点\u类型{
int数据;
结构节点类型*下一步;
}节点;
int main()
{
typedef节点*列表;
表头、临时工;
char ch;
int n;
head=NULL;
printf(“输入数据?(是/否)\n”);
scanf(“%c”和“ch”);
while(ch='y'| ch='y')
{
printf(“\n输入数据:”);
scanf(“%d”和“&n”);
temp=(list)malloc(sizeof(node));
温度->数据=n;
温度->下一步=头部;
压头=温度;
printf(“输入更多数据?(y/n)\n”);
scanf(“%c”和“ch”);
}
温度=水头;
while(temp!=NULL)
{
printf(“%d”,临时->数据);
温度=温度->下一步;
}
返回0;
}
更改此项:
scanf(“%c”和&ch)到这个
scanf(“%c”和&ch)

代码不接受任何输入的原因是因为scanf使用了缓冲区中的换行符。在代码> %c>代码>之前的空白空间导致SCANFF()在读取字符之前跳过缓冲区的空白和换行符。

谢谢。现在可以用了:D