Code:
#include <stdio.h>
typedef struct _Book {
char* author; /* better set statically like char author[30] */
char* title; /* better set statically */
char* isbn; /* better set statically */
int edition;
} Book;
int main()
{
int howmanyrecords;
int counter=0;
printf("How Many Record you want ?");
scanf("%d",&howmanyrecords);
Book *pbook[howmanyrecords];
for(counter=0;counter< howmanyrecords;counter++) /* max record: count from 0 to MAX - 1 */
{
pbook[counter] = (Book*)malloc(sizeof(Book));
printf("counter number is %d \n",counter + 1); /* counter = index + 1 */
printf("enter author\n");
/* if dynamically, then allocate memory first */
scanf("%s",pbook[counter]->author);
/* if dynamically, then allocate memory first */
printf("enter title\n");
scanf("%s",pbook[counter]->title);
/* if dynamically, then allocate memory first */
printf("enter isbn\n");
scanf("%s",pbook[counter]->isbn);
/* if dynamically, then allocate memory first */
printf("enter edition\n");
scanf("%d",pbook[counter]->edition);
}
for (counter=0;counter < howmanyrecords;counter++) /* not 0 */
{
printf ("record %d author is %s and the title is %s and the isbn %s is and the edition is%d\n"
,counter,pbook[counter]->author,pbook[counter]->title,pbook[counter]->isbn,pbook[counter]->edition);
}
return 0;
}