我正在尝试在 Visual stuido 中运行以下代码。请执行此代码,然后在此处键入的代码下方阅读我的经验。
#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],向前移动它会在不允许用户键入名称的地方为书名打印一个空格。