【发布时间】:2021-06-05 01:56:11
【问题描述】:
对于循环i = 2 和i = 3,我无法为本书的name 输入。
它正在被跳过。 i = 1 的第一个输入运行得非常好。
我的代码:
#include<stdio.h>
typedef struct book
{
char name[100];
float price;
int pages;
}bk;
int main(void)
{
int i;
bk b[100];
// b1, b2, b3;
for(i=1;i<=3;i++)
{
printf("Enter name of book %d: ",i);
gets(b[i].name);
printf("Enter price of book %d: ",i);
scanf("%f",&b[i].price);
printf("Enter pages of book %d:",i);
scanf("%d",&b[i].pages);
}
printf("\nYour inputs are:");
for(i=1;i<=3;i++)
{
printf("\nName of book %d: %s",i,b[i].name);
printf("\nPrice of book %d: %f",i,b[i].price);
printf("\nPages of book %d: %d",i,b[i].pages);
}
return 0;
}
我应该如何解决这个问题?
【问题讨论】:
标签: c string input struct structure