Visualstuidoで次のコードを実行しようとしています。このコードを実行してから、ここに入力したコードの下で私の経験を読んでください。
#include <stdio.h>
#include <conio.h>
main()
{
int i;
struct book
{
char name;
float price;
int pages;
};
struct book b[3];
printf("Enter the names prices & no. of pages of 3 books \n");
for (i = 0; i<=2; i++)
{
printf("name of book %d : ", i +1);
scanf("%c", &b[i].name);
printf("price of book %d : ", i +1);
scanf("%f", &b[i].price);
printf("pages in book %d : ", i +1);
scanf("%d", &b[i].pages);
}
for (i = 0; i<=2; i++)
{
printf("Name of book : %c, Price of book: %f, Pages in book : %d \n", b[i].name, b[i].price, b[i].pages);
}
printf("Press any key to continue");
getch();
}
void linkfloat()
{
float a =0, *b;
b = &a;
a = *b;
}
ご覧のとおり、ユーザーに本の名前、ページ番号、価格を尋ねますが、Visual Basicでコードを実行すると、ユーザーが価格とページ番号を入力できる一方で、本b2以降の名前を入力できない場合があります。同じ本b[i]の場合、先に進むと、ユーザーが名前を入力できない場所に本名の空白スペースが印刷されます。