Array of Structures

Suppose we have to store data of 100 books we would be required to use 100 different structure variables from b1 to b100, which is definitely not very convenient. A better approach would be to use an array of structures.

Example (how to use an array of structures)

#include <stdio.h>
int main() {
	struct book {
		char name;
		int price;
		int pages;
	};
	struct book b[100];
	int i;
	for (i = 0; i <= 99; i++) {
		printf("\nEnter name, price and pages ");
		scanf("%c %d %d", &b[i].name, &b[i].price, &b[i].pages);
	}
	for (i = 0; i <= 99; i++)
		printf("\n%c %d %d", b[i].name, b[i].price, b[i].pages);

getchar();
return 0;
}