From 7d1cf291deda94e44be525236195d835f7c8d35b Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 6 Feb 2019 08:02:45 +0100 Subject: Write contact list --- contactList.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'contactList.c') 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; +} -- cgit v1.2.3