aboutsummaryrefslogtreecommitdiff
path: root/contactList.c
diff options
context:
space:
mode:
Diffstat (limited to 'contactList.c')
-rw-r--r--contactList.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/contactList.c b/contactList.c
index cbc3b24..4369926 100644
--- a/contactList.c
+++ b/contactList.c
@@ -63,8 +63,7 @@ int addContact(const contact* cnct) {
memcpy(&contactList[nbContacts-1],cnct, sizeof *cnct);
}
-
-int fillContactList(char* filename) {
+int fillContactList(const char* filename) {
FILE* file = fopen(filename, "r");
nbContacts = 0;
@@ -167,7 +166,23 @@ int fillContactList(char* filename) {
}
}
}
+ fclose(file);
return 0;
}
+int writeContactList(const char* filename) {
+ FILE* file = fopen(filename, "w");
+
+ if( !file ) {
+ fprintf(stderr, "Unable to read contact file (%s)\n", filename);
+ return 1;
+ }
+
+ for( int i = 0 ; i < nbContacts ; i++) {
+ fprintf(file, "%s;;%s;;%s\n", contactList[i].name, contactList[i].display_name, contactList[i].number);
+ }
+ fclose(file);
+
+ return 0;
+}