Guest User

Untitled

a guest
Feb 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. typedef char NAME[41];
  2.  
  3. typedef struct date
  4. {
  5. int month;
  6. int day;
  7. int year;
  8. } DATE;
  9.  
  10. typedef struct person
  11. {
  12. NAME name;
  13. int age;
  14. float height;
  15. DATE bday;
  16. } PERSON;
  17.  
  18. typedef struct list
  19. {
  20. void *data;
  21. struct list *next;
  22. } LIST;
  23.  
  24. int main(void)
  25. {
  26. PERSON *person;
  27.  
  28. int num;
  29. puts("Enter the initial number of records:");
  30. if (scanf("%d", &num) < 1)
  31. num = DEF_NUM;
  32.  
  33. while (num-- > 0)
  34. {
  35. person = (PERSON *) malloc(sizeof(PERSON));
  36. inputPersonalData(person);
  37. addPersonalDataToDatabase(person);
  38. }
  39.  
  40. void inputPersonalData(PERSON *person)
  41. {
  42. printf("enter the name");
  43. scanf("%s", person->name);
  44. printf("enter the age");
  45. scanf("%d", &person->age);
  46. printf("enter the height");
  47. scanf("%f", &person->height);
  48. printf("enter the birthdate");
  49. scanf("%d/%d/%d", &person->bday.month, &person->bday.day, &person->bday.year);
  50.  
  51. printf("%s %d %f %d %d %d", person->name, person->age, person->height, person->bday.month,
  52. person->bday.day, person->bday.year);
  53.  
  54. // head->data = &person->name;
  55. // printf("%p", head->data);
  56.  
  57. }
  58.  
  59. void addPersonalDataToDatabase(PERSON *person)
  60. {
  61.  
  62. // add(head, tail, person);
  63. // need help here once I call the function add it always leaves
  64. // with exit code 11
  65.  
  66. }
  67.  
  68. void add(LIST **head, LIST **tail, void *data)
  69. {
  70. if (*tail == NULL)
  71. {
  72. *head = *tail = (LIST *) malloc(sizeof(LIST));
  73. (*head)->data = data;
  74. (*head)->next = NULL;
  75. } else
  76. {
  77. (*tail)->next = (LIST *) malloc(sizeof(LIST));
  78. *tail = (*tail)->next;
  79. (*tail)->data = data;
  80. (*tail)->next = NULL;
  81. }
  82. }
Add Comment
Please, Sign In to add comment