-
Notifications
You must be signed in to change notification settings - Fork 0
/
contacts.c
119 lines (102 loc) · 3.04 KB
/
contacts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* -------------------------------------------
Name: Eric Rabiner
Student number: 038806063
Email: [email protected]
Section: L
Date: Tuesday, Nov. 13, 2018
----------------------------------------------
Assignment: 2
Milestone: 4
---------------------------------------------- */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "contacts.h"
#include "contactHelpers.h"
#include <string.h>
// +-------------------------------------------------+
// | NOTE: Copy/Paste your Assignment-2 Milestone-3 |
// | source code below... |
// +-------------------------------------------------+
// getName:
void getName(struct Name * name) {
int flag;
printf("Please enter the contact's first name: ");
scanf("%30[^\n]", (*name).firstName);
clearKeyboard();
printf("Do you want to enter a middle initial(s)? (y or n): ");
flag = yes();
if (flag == 1) {
printf("Please enter the contact's middle initial(s): ");
scanf("%6[^\n]", (*name).middleInitial);
clearKeyboard();
}
else
strcpy((*name).middleInitial, "");
printf("Please enter the contact's last name: ");
scanf("%35[^\n]", (*name).lastName);
clearKeyboard();
}
// getAddress:
void getAddress(struct Address * address) {
int flag;
int num;
printf("Please enter the contact's street number: ");
(*address).streetNumber = getInt();
num = (*address).streetNumber;
while (num < 0) {
printf("Please enter the contact's street number: ");
(*address).streetNumber = getInt();
num = (*address).streetNumber;
}
printf("Please enter the contact's street name: ");
scanf("%40[^\n]", (*address).street);
clearKeyboard();
printf("Do you want to enter an apartment number? (y or n): ");
flag = yes();
if (flag == 1) {
printf("Please enter the contact's apartment number: ");
(*address).apartmentNumber = getInt();
num = (*address).apartmentNumber;
while (num < 0) {
printf("Please enter the contact's apartment number: ");
(*address).apartmentNumber = getInt();
num = (*address).apartmentNumber;
}
}
else
(*address).apartmentNumber = 0;
printf("Please enter the contact's postal code: ");
scanf("%7[^\n]", (*address).postalCode);
clearKeyboard();
printf("Please enter the contact's city: ");
scanf("%40[^\n]", (*address).city);
clearKeyboard();
}
// getNumbers:
void getNumbers(struct Numbers * numbers) {
int flag;
printf("Please enter the contact's cell phone number: ");
getTenDigitPhone((*numbers).cell);
printf("Do you want to enter a home phone number? (y or n): ");
flag = yes();
if (flag == 1) {
printf("Please enter the contact's home phone number: ");
getTenDigitPhone((*numbers).home);
}
else
strcpy((*numbers).home, "");
printf("Do you want to enter a business phone number? (y or n): ");
flag = yes();
if (flag == 1) {
printf("Please enter the contact's business phone number: ");
getTenDigitPhone((*numbers).business);
}
else
strcpy((*numbers).business, "");
}
// getContact
void getContact(struct Contact * contact) {
getName(&(*contact).name);
getAddress(&(*contact).address);
getNumbers(&(*contact).numbers);
}