Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2.  
  3.  
  4. typedef struct {
  5. char day[3];
  6. char month[3];
  7. char year[5];
  8. } DateOfBirth;
  9.  
  10. typedef struct {
  11. char* lastName;
  12. char* firstName;
  13. char* stName;
  14. char* email;
  15. char* phoneNum;
  16. DateOfBirth dateOfBirth;
  17. } Contact;
  18.  
  19. extern int Count;
  20. extern Contact Contacts[100];
  21.  
  22. DateOfBirth *BirthdayConstructor(char* s);
  23. void add_new_contact();
  24.  
  25. DateOfBirth *BirthdayConstructor(char* s)
  26. {
  27. DateOfBirth *birthday = malloc(sizeof(DateOfBirth));
  28. int i = 0;
  29. char *p = strtok(s,"/'\'- ");
  30. while(p)
  31. {
  32. if (i == 0) {
  33. strcpy(birthday->day, p);
  34. }
  35. else if (i == 2) {
  36. strcpy(birthday->month, p);
  37. }
  38. else if (i == 4) {
  39. strcpy(birthday->year, p);
  40. }
  41. i++;
  42. }
  43. return birthday;
  44. }
  45.  
  46. void add_new_contact()
  47. {
  48. // VALIDATIONS TO BE DONE
  49.  
  50. char birthday[11];
  51.  
  52. Contact *contact = malloc(sizeof(Contact));
  53. printf("Please enter the contact first name: \n");
  54. scanf("%s", contact->firstName);
  55. printf("Please enter the contact last name: \n");
  56. scanf("%s", contact->lastName);
  57. printf("Please enter the contact number: \n");
  58. scanf("%s", contact->phoneNum);
  59. printf("Please enter the contact email: \n");
  60. scanf("%s", contact->email);
  61. printf("Please enter the contact address: \n");
  62. scanf("%s", contact->stName);
  63. printf("Please enter the contact birthday: \n");
  64. scanf("%s", birthday);
  65.  
  66. DateOfBirth *bd;
  67. bd = BirthdayConstructor(birthday);
  68. contact->dateOfBirth = *bd;
  69. Contacts[Count] = *contact;
  70. Count++;
  71.  
  72. }
  73.  
  74. #ifndef PHONEBOOK_FUNCTIONS_H
  75. #define PHONEBOOK_FUNCTIONS_H
  76.  
  77. #endif //PHONEBOOK_FUNCTIONS_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement