I am trying to use array of structures to store the information of 5 books.I was reading a book that ia quite common in Indian sub-continent i.e. "Let us C" just to understand what is C so that i am uch prepare to study K&R.While i was trying to implement one of the example for array of structures, i make required changes in the example but still i am getting certain errors and i am unable to find the error.
#include<stdio.h>
//void inkfloat(); commented as i am not using any float variable
int main()
{
int i;
struct book
{
char bookname[30];
char authorname[30];
int price;
int book_id;
};
struct book b[5];
for(i=0;i<=4;i++)
{
printf("Enter bookname,authorname, price and book_id for book");
scanf("%s %s %d %d",&b[i].bookname,&b[i].authorname,&b[i].price,&b[i].book_id);
}
for(i=0;i<=4;i++)
{
printf(" %s %s %d %d \n",b[i].bookname,b[i].authorname,b[i].price,b[i].book_id);
}
return 0;
}
/*void inkfloat()
{
float a=0,*b;
b=&a;
a=*b;
}*/
I am getting output as
Enter bookname,authorname, price and book_id for book shailendra
Enter bookname,authorname, price and book_id for book let us c
Enter bookname,authorname, price and book_id for bookEnter bookname,authorname, price and book_id for bookEnter bookname,authorname, price and book_id for bookyaswat kanetkar
s, �, -1218811592, -1216872840 l, :, -1218241152, -1218240426 u, ~, -1216874216, 0 c, �, 134513259, 0 y, , -1218653802, -1217138700
Along with that i am unable to understand the use of inkfloat variable which according to the book is used when we are using float variable inside our code and if didn't use it when using float variable a error will come"Floating points format not linked"
i had seen An array of structures and other related questions on stackoverflow, but cant resolve what error i am having in my code.