标题:刚学习完链表,做个练习,输入时出现问题
只看楼主
a631908999
Rank: 1
等 级:新手上路
帖 子:9
专家分:6
注 册:2014-5-18
结帖率:100%
 问题点数:0 回复次数:2 
刚学习完链表,做个练习,输入时出现问题
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
    struct Infor
    {
        int num;
        char name[10];
        int age;
        struct Infor *next;
    };
    struct Infor people;
    struct Infor *first,*now,*last;
    first = now = last = NULL;
    char test;
    for(;;)                //输入信息
    {
        if(first == NULL)
            first = now;
   
        if(last != NULL)
            last->next = now;
        printf("请输入编号:\n");
         scanf("%d",&people.num);
        printf("请输入名字:\n");
         scanf("%s",people.name);
        printf("请输入年龄:\n");
         scanf("%d",&people.age);
        now = (struct Infor*)malloc(sizeof(people));
        if(malloc == NULL)
            exit(1);
        now = &people;
        now->next = NULL;
        last = now;


       printf("继续输入信息?(Y/N)\n");
         scanf("%c",&test);
        if(test == 'n')
        break;

    }
   
   
    now = first;
    while(now != NULL)            //输出信息
        {
            printf("%d号是%s,,%d岁\n",now->num,now->name,now->age);
            last = now;
            now = now->next;
            free(last);
        }
    return 0;
}

为什么系统在打印“是否继续输入”后直接跳过判断而转向输入下一组数据??
搜索更多相关主题的帖子: include people 信息 
2014-05-29 18:22
张小齊
Rank: 2
等 级:论坛游民
帖 子:14
专家分:46
注 册:2014-5-23
得分:0 
未清除缓存区
试试    fflush(stdin);
2014-05-29 22:29
a631908999
Rank: 1
等 级:新手上路
帖 子:9
专家分:6
注 册:2014-5-18
得分:0 
回复 2 楼 张小
好的,谢谢
2014-06-01 11:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-432245-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.079395 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved