-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontacts.c
executable file
·162 lines (126 loc) · 3.99 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* -------------------------------------------
Name:Badal Sarkar
Student number:<137226189>
Email:[email protected]
Section:Q
Date:December 01, 2018
----------------------------------------------
Assignment: 2
Milestone: 4
---------------------------------------------- */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include "contacts.h"
#include "contactHelpers.h"
#include <string.h>
//Function declarations
/* ++++++++++++++++++++++++++++++++++++++++
getName:
This function will get user name details
++++++++++++++++++++++++++++++++++++++++++*/
void getName(struct Name* name)
{
// get first name
printf("Please enter the contact's first name: ");
scanf("%30[^\n]", name->firstName);
// Clearing the input buffer so that next input is
// taken from user in stead of the input buffer
clearKeyboard();
// get middle initial
printf("Do you want to enter a middle initial(s)? (y or n): ");
if (yes() == 1) {
printf("Please enter the contact's middle initial(s): ");
scanf("%6[^\n]", name->middleInitial);
// Clearing the input buffer so that next input is
// taken from user in stead of the input buffer
clearKeyboard();
}
// get last name
printf("Please enter the contact's last name: ");
scanf("%35[^\n]", name->lastName);
// Clearing the input buffer so that next input is
// taken from user in stead of the input buffer
clearKeyboard();
}
/* +++++++++++++++++++++++++++++++++++
getAddress:
this function will get user address
+++++++++++++++++++++++++++++++++++++*/
void getAddress(struct Address* address)
{
// variable used to check if the integer is positive or negative
int positiveInt;
// get street number
// number must be positive integer
// if user enter negative integer, show error message
do {
printf("Please enter the contact's street number: ");
positiveInt = getInt();
if (positiveInt > 0) {
address->streetNumber = positiveInt;
}
} while (positiveInt < 0);
// get street name
printf("Please enter the contact's street name: ");
scanf("%40[^\n]", address->street);
// Clearing the input buffer
clearKeyboard();
// get apt. number
// number must be positive integer
// if user enter negative integer, show error message
printf("Do you want to enter an apartment number? (y or n): ");
if (yes() == 1) {
do {
printf("Please enter the contact's apartment number: ");
positiveInt = getInt();
if (positiveInt > 0) {
address->apartmentNumber = positiveInt;
}
} while (positiveInt < 0);
}
// get postal code
printf("Please enter the contact's postal code: ");
scanf("%7[^\n]", address->postalCode);
// Clearing the input buffer
clearKeyboard();
// get city
printf("Please enter the contact's city: ");
scanf("%40[^\n]", address->city);
// Clearing the input buffer
clearKeyboard();
} // End of function
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
getNumbers:
this function will get phone numbers from user
NOTE: Also modify this function so the cell number is
mandatory (don't ask to enter the cell number)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void getNumbers(struct Numbers* number)
{
// get cell phone number
printf("Please enter the contact's cell phone number: ");
getTenDigitPhone(number->cell);
// get home phone number
printf("Do you want to enter a home phone number? (y or n): ");
if (yes() == 1) {
printf("Please enter the contact's home phone number: ");
getTenDigitPhone(number->home);
}
// get business phone number
printf("Do you want to enter a business phone number? (y or n): ");
if (yes() == 1) {
printf("Please enter the contact's business phone number: ");
getTenDigitPhone(number->business);
}
}
/* +++++++++++++++++++++++++++++++++++++++++++++++
getContact
this function wil get contact details from user
and update the releted constructs
++++++++++++++++++++++++++++++++++++++++++++++++*/
void getContact(struct Contact *contact)
{
getName(&contact->name);
getAddress(&contact->address);
getNumbers(&contact->numbers);
}