我是一个c语言的初学者。今天我遇到了一个问题。根据书上的介绍,如果我们输入以下内容:
Enter names, prices and no. of pages of 3 books
A 100.00 354
C 256.50 682
F 233.70 512
输出结果将如下所示。
And this is what you entered
A 100.000000 354
C 256.500000 682
F 233.700000 512
当程序运行时突然终止。
代码如下:
#include<stdio.h>
#include <ctype.h>
main( )
{
struct book
{
char name ;
float price ;
int pages ;
} ;
struct book b1, b2, b3 ;
printf ( "\nEnter names, prices & 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 ( "\nAnd this is what you entered" ) ;
printf ( "\n%c %f %d", b1.name, b1.price, b1.pages ) ;
printf ( "\n%c %f %d", b2.name, b2.price, b2.pages ) ;
printf ( "\n%c %f %d", b3.name, b3.price, b3.pages ) ;
}
int main(void)
,并以return 0;
结尾。 - abelenky