Advertisement
Guest User

Untitled

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