我正在用C语言开发一个关于图书馆管理系统的迷你项目。但我在使用结构时遇到问题,我花了很多时间去理解,但我无法理解。不可预测的输出
下面是一个代码:
struct book
{
char name;
float price;
int pages;
}b1,b2,b3;
int main()
{
clrscr();
printf("Enter names,price & no.of pages of 3 books\n");
scanf("%c%f%d",&b1.name,&b1.price,&b1.pages);
scanf("%c%f%d",&b2.name,&b2.price,&b2.pages);
scanf("%c%f%d",&b3.name,&b3.price,&b3.pages);
printf(" %c %f %d",b1.name,b1.price,b1.pages);
printf(" %c %f %d",b2.name,b2.price,b2.pages);
printf(" %c %f %d",b3.name,b3.price,b3.pages);
getch();
return 0;
}
输出:
Enter names,price & no.of pages of 3 books
a 3.3 2
b 2.2 3
a 0.000000 2
0.000000 0 b 0.000000 3
有两个混淆:
- 为什么
scanf("%c%f%d",&b3.name,&b3.price,&b3.pages);
未执行? - 难以预测的输出?
请采取适当缩进代码的时间。如果你不能费尽心思编写你的问题,为什么我们应该烦恼去阅读它? – meagar 2013-02-19 18:21:32
你是什么意思“无法正常访问”? – 2013-02-19 18:21:41