C structures programming involves declaring a structure in a C program after macro definitions before declaring any function. C structure is a collection of different datatypes within single datatype of structure type.Following example illustrate the use of structures in C programming.
C structures programming example:
This C program involves a structure named cricketer, which is used to store name and batting average of a cricketer.Users are asked to enter details of 10 players including their name and batting average. Program then sorts the list and display list in descending order according to batting average of cricketers.
void bsort(struct cricketer a);
void display(struct cricketer a);
struct cricketer a;
/*To enter the details of 11 players*/
printf("\n\nenter the details of %dth cricketer",i+1);
printf("\nenter runs: ");
printf("enter name: ");
/*To sort list of cricketers according to the run scrored*/
void bsort(struct cricketer a)
struct cricketer temp;
/*To display the details of cricketers accoring to runs*/
void display(struct cricketer a)
printf("\nthe details are\n");
Download Source Code: Cricketer structures programming
Download Executable File: cricketer structures programming
Batting average of a particular player is matched with batting average of other players. Following that player in the list. If its batting average is lesser than any other player in the list than their position are swapped using basic structures programming logic.Each time batting average of a player is compared to the players following him.
If you face any problem regarding implementation of structures programming in C, feel free to comment below or discuss it on our 24*7 active facebook group.