I am trying to run the following code in Visual stuido. Please execute this code and then read my experience in below the code typed here.
#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;
}
As you can see it asks user the book name, pages nos and price, but it so happens that when you run code in visual basic, it doesn not allow to type name for book b2 onwards while it allows user to type price and page no for the same book b[i], moving forward it prints a blank space for book name where it did not allow user to type the name.
void main(void);.mainisn't one of the canonical forms, andconio/getchshould have disappeared about the same time as Borland/Inprise/Enchilada or whatever they call themselves nowadays.