#include<stdio.h>
int main()
{
char name[3];
float price[3];
int pages[3];
int i;
for(i=0; i<3; i++)
{
printf("enter the title, price and pages of three books\n");
fflush(stdin);
scanf("%c %f %d", &name[i], &price[i], &pages[i]);
printf("the value of i is %d\n", i);
}
for(i=0; i<3; i++)
{
printf("the title of the book is %c, price of the book is %f,
number of pages of the book is %d", name[i], price[i], pages[i]);
}
return 0;
}
我得到的输出是:
the title of the book is a, price of the book is 122.000000, number of pages of the book is 22
the title of the book is , price of the book is 0.000000, number of pages of the book is 134520820
the title of the book is b, price of the book is 0.000000, number of pages of the book is -10
我想要得到的是:
the title of the book is Harry Potter, price of the book is 20, number of pages of the book is 22
the title of the book is 50 shades of grey, price of the book is 30, number of pages of the book is 60
the title of the book is Game of Thrones, price of the book is 40, number of pages of the book is 200