aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2019-02-06 08:02:45 +0100
committerache <ache@ache.one>2019-02-06 08:02:45 +0100
commit7d1cf291deda94e44be525236195d835f7c8d35b (patch)
tree7bbf4002e803b265f2b3955bf6d4d500d6ad3368
parentDebug mode (diff)
Write contact list
-rw-r--r--contactList.c19
-rw-r--r--contactList.h13
2 files changed, 20 insertions, 12 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;
+}
diff --git a/contactList.h b/contactList.h
index c5cf10c..6d72dee 100644
--- a/contactList.h
+++ b/contactList.h
@@ -22,12 +22,12 @@ typedef struct contact {
// Params: The CSV filename (separator ';', unexcaped string, so ';' is forbiden in value)
// Return: 0 if success, >0 if error
-int fillContactList(char* cvs_file_in);
+int fillContactList(const char* cvs_file_in);
// Params: A valide filename
// Return: 0 if success, >0 if error
-int writeContactList(char* cvs_file_in);
+int writeContactList(const char* cvs_file_in);
// Find a contact
// Params: A SIM Number
@@ -50,14 +50,7 @@ int addContact(const contact*);
// Delete a contact
// Params: A String which is a valide contact SIM number
// Return: 0 if success, >0 otherwise
-int deleteContactFromNumber(const char*);
-
-
-// Delete a contact from his name
-// Params: A String which is a valide contact SIM number
-// Return: 0 if success, >0 otherwise
-int deleteContactFromName(const char*);
-
+int deleteContact(void);
// Sort the contact list
// Params : Nothing