Basics of a family tree 2 : Tree « Data Structure Algorithm « 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
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
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
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C / ANSI-C » Data Structure Algorithm » TreeScreenshots 
Basics of a family tree 2

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

struct Cat *getCat(void);

struct Date
{
   int day;
   int month;
   int year;
};

struct Cat
{
   struct Date dob;
   char name[20];
   char father[20];
   char mother[20];
   struct Cat *next;
   struct Cat *previous;
};

int main()
{
   struct Cat *first = NULL;
   struct Cat *current = NULL;
   struct Cat *last = NULL;

   char more = '\0';
   int i =0;
   for(i =0;i<;i++ )
   {
     current = getCat();
     if(first == NULL){
       first = current;
       last = current;
     }else {
       last->next = current;
       current->previous = last;
       last = current;
     }
   }

   while (current  != NULL)
   {
     printf("\n%s was born %d/%d/%d, and has %s and %s as parents.",
              current->name, current->dob.day, current->dob.month,
              current->dob. year, current->father,  current->mother );

     last = current;     /* Save pointer to enable memory to be freed */
     current = current->previous;  /* current points to previous list */
     free(last);
   }
}

struct Cat *getCat(void)
{
   struct Cat *temp;

   temp = (struct Cat*malloc(sizeof(struct Cat));

   printf("\nEnter the name of the person: ");
   scanf("%s", temp -> name );

   printf("\nEnter %s's date of birth (day month year); ", temp->name);
   scanf("%d %d %d", &temp->dob.day, &temp->dob.month, &temp->dob.year);

   printf("\nWho is %s's father? ", temp->name );
   scanf("%s", temp->father );

   printf("\nWho is %s's mother? ", temp -> name );
   scanf("%s", temp -> mother );
   temp->next = temp->previous = NULL;

   return temp;
}


           
       
Related examples in the same category
1. Basics of a family tree
2. Investigating the family
3. Displays a binary tree
w_w_w__.___ja_v___a__2_s__.__c___o__m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.