Exercising the horses: Structure array declaration : Structure Array « Structure « C / ANSI-C

C / ANSI-C
1. assert.h
2. Console
3. ctype.h
4. Data Structure Algorithm
5. Data Type
6. Development
7. File
8. Function
9. Language Basics
10. Macro Preprocessor
11. Math
12. math.h
13. Memory
14. Pointer
15. setjmp.h
16. signal.h
17. Small Application
18. stdio.h
19. stdlib.h
20. String
21. string.h
22. Structure
23. time.h
24. wctype.h
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C / ANSI-C » Structure » Structure ArrayScreenshots 
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 = ; 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 );
   }
}


           
       
Related examples in the same category
1. Using a linked list of structures representing a person's name
2. Daisy chaining the horses both waysDaisy chaining the horses both ways
3. A simple mailing list example using an array of structuresA simple mailing list example using an array of structures
ww_w.j_a_va2s_.c_o___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.