Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4.  
  5. struct Cat *getCat(void);
  6.  
  7. struct Date
  8. {
  9. int day;
  10. int month;
  11. int year;
  12. };
  13.  
  14. struct Cat
  15. {
  16. struct Date dob;
  17. char name[20];
  18. char father[20];
  19. char mother[20];
  20. struct Cat *next;
  21. struct Cat *previous;
  22. };
  23.  
  24. int main()
  25. {
  26. struct Cat *first = NULL;
  27. struct Cat *current = NULL;
  28. struct Cat *last = NULL;
  29.  
  30. char more = '\0';
  31. int i =0;
  32. for(i =0;i<5 ;i++ )
  33. {
  34. current = getCat();
  35. if(first == NULL){
  36. first = current;
  37. last = current;
  38. }else {
  39. last->next = current;
  40. current->previous = last;
  41. last = current;
  42. }
  43. }
  44.  
  45. while (current != NULL)
  46. {
  47. printf("\n%s was born %d/%d/%d, and has %s and %s as parents.",
  48. current->name, current->dob.day, current->dob.month,
  49. current->dob. year, current->father, current->mother );
  50.  
  51. last = current; /* Save pointer to enable memory to be freed */
  52. current = current->previous; /* current points to previous list */
  53. free(last);
  54. }
  55. }
  56.  
  57. struct Cat *getCat(void)
  58. {
  59. struct Cat *temp;
  60.  
  61. temp = (struct Cat*) malloc(sizeof(struct Cat));
  62.  
  63. printf("\nEnter the name of the person: ");
  64. scanf("%s", temp -> name );
  65.  
  66. printf("\nEnter %s's date of birth (day month year); ", temp->name);
  67. scanf("%d %d %d", &temp->dob.day, &temp->dob.month, &temp->dob.year);
  68.  
  69. printf("\nWho is %s's father? ", temp->name );
  70. scanf("%s", temp->father );
  71.  
  72. printf("\nWho is %s's mother? ", temp -> name );
  73. scanf("%s", temp -> mother );
  74. temp->next = temp->previous = NULL;
  75.  
  76. return temp;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement