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[15];
- char firstName[15];
- char stName[100];
- char email[256];
- char phoneNum[11];
- DateOfBirth dateOfBirth;
- } Contact;
- extern int Count;
- extern Contact Contacts[];
- 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 == 1) {
- strcpy(birthday->month, p);
- }
- else if (i == 2) {
- strcpy(birthday->year, p);
- }
- p = strtok(NULL, "/'\'- ");
- i++;
- }
- return birthday;
- }
- void add_new_contact()
- {
- // VALIDATIONS TO BE DONE
- char birthday[11];
- Contact *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 (" %[^\n]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++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement