Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- char day[3];
- char month[3];
- char year[5];
- } DateOfBirth;
- typedef struct {
- char* lastName;
- char* firstName;
- char* stName;
- char* email;
- char* phoneNum;
- DateOfBirth dateOfBirth;
- } Contact;
- extern int Count;
- extern Contact Contacts[100];
- DateOfBirth *BirthdayConstructor(char* s);
- void add_new_contact();
- DateOfBirth *BirthdayConstructor(char* s)
- {
- DateOfBirth *birthday = malloc(sizeof(DateOfBirth));
- int i = 0;
- char *p = strtok(s,"/'\'- ");
- while(p)
- {
- if (i == 0) {
- strcpy(birthday->day, p);
- }
- else if (i == 2) {
- strcpy(birthday->month, p);
- }
- else if (i == 4) {
- strcpy(birthday->year, p);
- }
- i++;
- }
- return birthday;
- }
- void add_new_contact()
- {
- // VALIDATIONS TO BE DONE
- char birthday[11];
- Contact *contact = malloc(sizeof(Contact));
- printf("Please enter the contact first name: \n");
- scanf("%s", contact->firstName);
- printf("Please enter the contact last name: \n");
- scanf("%s", contact->lastName);
- printf("Please enter the contact number: \n");
- scanf("%s", contact->phoneNum);
- printf("Please enter the contact email: \n");
- scanf("%s", contact->email);
- printf("Please enter the contact address: \n");
- scanf("%s", contact->stName);
- printf("Please enter the contact birthday: \n");
- scanf("%s", birthday);
- DateOfBirth *bd;
- bd = BirthdayConstructor(birthday);
- contact->dateOfBirth = *bd;
- Contacts[Count] = *contact;
- Count++;
- }
- #ifndef PHONEBOOK_FUNCTIONS_H
- #define PHONEBOOK_FUNCTIONS_H
- #endif //PHONEBOOK_FUNCTIONS_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement