鱼C论坛

 找回密码
 立即注册
查看: 2361|回复: 1

[已解决]输入

[复制链接]
发表于 2022-12-7 15:13:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
为什么直接不进行输入,直接跳过,第31行
#include <stdio.h>
#include <stdlib.h>
struct Date
{
        int n;
        int y;
        int r;
};
struct Record
{
        char k[16];
        int age;
        struct Date a;
        struct Date b;
};
void shur(struct Record *q[],int i)
{
        char ch;
        int j;
        for(j=0;j<i;j++)
        {
                q[j]=(struct Record *)malloc(sizeof(struct Record));
        }
        for(j=0;j<i;j++)
        {
                printf("请输入姓名:");
                scanf("%s",q[j]->k); 
                printf("请输入年龄:");
                scanf("%d",&q[j]->age); 
                printf("是否打了第一针疫苗(y/n):"); 
                scanf("%c",&ch);
                if(ch=='y')
                {
                        scanf("%d-%d-%d",&q[j]->a.n,&q[j]->a.y,&q[j]->a.r);
                }
                else
                {
                        continue;
                }
                printf("是否打了第二针疫苗(y/n):");
                scanf("%c",&ch);
                if(ch=='y')
                {
                        scanf("%d-%d-%d",&q[j]->b.n,&q[j]->b.y,&q[j]->b.r);
                }
                else
                {
                        continue;
                }
        }
}
int main()
{
        int i;
        scanf("%d",&i);
        struct Record *q[i];
        shur(q,i);
        return 0;
}
最佳答案
2022-12-7 15:16:54
#include <stdio.h>
#include <stdlib.h>
struct Date
{
        int n;
        int y;
        int r;
};
struct Record
{
        char k[16];
        int age;
        struct Date a;
        struct Date b;
};
void shur(struct Record *q[],int i)
{
        char ch;
        int j;
        for(j=0;j<i;j++)
        {
                q[j]=(struct Record *)malloc(sizeof(struct Record));
        }
        for(j=0;j<i;j++)
        {
                printf("请输入姓名:");
                scanf("%s",q[j]->k); 
                printf("请输入年龄:");
                scanf("%d",&q[j]->age); 
                printf("是否打了第一针疫苗(y/n):"); 
                fflush(stdin);/////////////////////////清除缓存,把'\n'消去,否则下面 scanf("%c",&ch);会接收'\n'
                scanf("%c",&ch);
                if(ch=='y')
                {
                        scanf("%d-%d-%d",&q[j]->a.n,&q[j]->a.y,&q[j]->a.r);
                }
                else
                {
                        continue;
                }
                printf("是否打了第二针疫苗(y/n):");
                fflush(stdin);/////////////////////////清除缓存,把'\n'消去,否则下面 scanf("%c",&ch);会接收'\n'
                scanf("%c",&ch);
                if(ch=='y')
                {
                        scanf("%d-%d-%d",&q[j]->b.n,&q[j]->b.y,&q[j]->b.r);
                }
                else
                {
                        continue;
                }
        }
}
int main()
{
        int i;
        scanf("%d",&i);
        struct Record *q[i];
        shur(q,i);
        return 0;
}
运行结果2.png
运行结果.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-7 15:16:54 | 显示全部楼层    本楼为最佳答案   
#include <stdio.h>
#include <stdlib.h>
struct Date
{
        int n;
        int y;
        int r;
};
struct Record
{
        char k[16];
        int age;
        struct Date a;
        struct Date b;
};
void shur(struct Record *q[],int i)
{
        char ch;
        int j;
        for(j=0;j<i;j++)
        {
                q[j]=(struct Record *)malloc(sizeof(struct Record));
        }
        for(j=0;j<i;j++)
        {
                printf("请输入姓名:");
                scanf("%s",q[j]->k); 
                printf("请输入年龄:");
                scanf("%d",&q[j]->age); 
                printf("是否打了第一针疫苗(y/n):"); 
                fflush(stdin);/////////////////////////清除缓存,把'\n'消去,否则下面 scanf("%c",&ch);会接收'\n'
                scanf("%c",&ch);
                if(ch=='y')
                {
                        scanf("%d-%d-%d",&q[j]->a.n,&q[j]->a.y,&q[j]->a.r);
                }
                else
                {
                        continue;
                }
                printf("是否打了第二针疫苗(y/n):");
                fflush(stdin);/////////////////////////清除缓存,把'\n'消去,否则下面 scanf("%c",&ch);会接收'\n'
                scanf("%c",&ch);
                if(ch=='y')
                {
                        scanf("%d-%d-%d",&q[j]->b.n,&q[j]->b.y,&q[j]->b.r);
                }
                else
                {
                        continue;
                }
        }
}
int main()
{
        int i;
        scanf("%d",&i);
        struct Record *q[i];
        shur(q,i);
        return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-20 20:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表