From b84ddbea51b1247117891be301667feb2fa8975e Mon Sep 17 00:00:00 2001 From: ache Date: Thu, 7 Feb 2019 10:59:50 +0100 Subject: Delete contact --- contactList.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'contactList.c') diff --git a/contactList.c b/contactList.c index 9c6640c..891054c 100644 --- a/contactList.c +++ b/contactList.c @@ -62,6 +62,17 @@ int addContact(const contact* cnct) { contactList = realloc(contactList, nbContacts * sizeof *contactList); memcpy(&contactList[nbContacts-1],cnct, sizeof *cnct); } +int deleteContact(contact* cnct) { + if( cnct->conversation ) { + *cnct->name = 0; + strcpy(cnct->display_name, cnct->number); + } else { + int index = cnct - contactList; + fprintf(stderr, "Index %d\n", index); + memmove(contactList+index, contactList + index + 1, (nbContacts-index-1) * sizeof(contact)); + nbContacts--; + } +} int fillContactList(const char* filename) { FILE* file = fopen(filename, "r"); -- cgit v1.2.3