1
/* It is not entering data into the third scanf() statement .*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(void)
{
struct book
{
char name;
int pages;
float price;
};
struct book a1,a2,a3,a4;
printf("Enter data into 3 books\n");
scanf("%c %d %f",&a1.name,&a1.pages,&a1.price);
scanf("%c %d %f",&a2.name,&a2.pages,&a2.price);
scanf("%c %d %f",&a3.name,&a3.pages,&a3.price);
printf(" you entered:\n");
printf("\n%c %d %f",a1.name,a1.pages,a1.price);
printf("\n%c %d %f",a2.name,a2.pages,a2.price);
printf("\n%c %d %f",a3.name,a3.pages,a3.price);
getch();
}
不要對'string'條目使用'scanf()'。改用'fgets()'。 – 2010-07-06 13:39:28
他沒有使用'scanf'作爲'string'條目。 – 2010-07-06 13:44:46
@ el.pescado:他編輯了他的帖子。他將'char name [100]'改爲'char name' – 2010-07-06 13:47:25