输入
为什么直接不进行输入,直接跳过,第31行#include <stdio.h>
#include <stdlib.h>
struct Date
{
int n;
int y;
int r;
};
struct Record
{
char k;
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=(struct Record *)malloc(sizeof(struct Record));
}
for(j=0;j<i;j++)
{
printf("请输入姓名:");
scanf("%s",q->k);
printf("请输入年龄:");
scanf("%d",&q->age);
printf("是否打了第一针疫苗(y/n):");
scanf("%c",&ch);
if(ch=='y')
{
scanf("%d-%d-%d",&q->a.n,&q->a.y,&q->a.r);
}
else
{
continue;
}
printf("是否打了第二针疫苗(y/n):");
scanf("%c",&ch);
if(ch=='y')
{
scanf("%d-%d-%d",&q->b.n,&q->b.y,&q->b.r);
}
else
{
continue;
}
}
}
int main()
{
int i;
scanf("%d",&i);
struct Record *q;
shur(q,i);
return 0;
} #include <stdio.h>
#include <stdlib.h>
struct Date
{
int n;
int y;
int r;
};
struct Record
{
char k;
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=(struct Record *)malloc(sizeof(struct Record));
}
for(j=0;j<i;j++)
{
printf("请输入姓名:");
scanf("%s",q->k);
printf("请输入年龄:");
scanf("%d",&q->age);
printf("是否打了第一针疫苗(y/n):");
fflush(stdin);/////////////////////////清除缓存,把'\n'消去,否则下面 scanf("%c",&ch);会接收'\n'
scanf("%c",&ch);
if(ch=='y')
{
scanf("%d-%d-%d",&q->a.n,&q->a.y,&q->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->b.n,&q->b.y,&q->b.r);
}
else
{
continue;
}
}
}
int main()
{
int i;
scanf("%d",&i);
struct Record *q;
shur(q,i);
return 0;
}
页:
[1]