Exercising the horses: Structure array declaration
#include <stdio.h> #include <ctype.h> struct cat { int age; int height; char name[20]; char father[20]; char mother[20]; }; int main() { struct cat myCat[50]; int hcount = 0; int i = 0; char test = '\0'; for(hcount = 0; hcount < 50 ; hcount++ ) { printf("\nDo you want to enter details of a%s cat (Y or N)? ", hcount?"nother " : "" ); scanf(" %c", &test ); if(tolower(test) == 'n') break; printf("\nEnter the name of the cat: " ); scanf("%s", myCat[hcount].name ); printf("\nHow old is %s? ", myCat[hcount].name ); scanf("%d", &myCat[hcount].age ); printf("\nHow high is %s ( in hands )? ", myCat[hcount].name ); scanf("%d", &myCat[hcount].height ); printf("\nWho is %s's father? ", myCat[hcount].name ); scanf("%s", myCat[hcount].father ); printf("\nWho is %s's mother? ", myCat[hcount].name ); scanf("%s", myCat[hcount].mother ); } for (i = 0 ; i < hcount ; i++ ) { printf("\n\n%s is %d years old, %d hands high,",myCat[i].name, myCat[i].age, myCat[i].height); printf(" and has %s and %s as parents.", myCat[i].father,myCat[i].mother ); } }
1. | Using a linked list of structures representing a person's name | ||
2. | Daisy chaining the horses both ways | ||
3. | A simple mailing list example using an array of structures |