From 70000500ad92afcd29e21017c4cfb9ccfd034f77 Mon Sep 17 00:00:00 2001 From: Ariadna Vigo Date: Fri, 18 Dec 2020 00:27:07 +0100 Subject: tasklst.c: now we can edit TaskLst entries --- tasklst.c | 13 +++++++++++++ tasklst.h | 1 + 2 files changed, 14 insertions(+) diff --git a/tasklst.c b/tasklst.c index d0916f1..83ffabf 100644 --- a/tasklst.c +++ b/tasklst.c @@ -124,6 +124,19 @@ task_lst_add_task(TaskLst *list, int status, const char *str) newtask->prev = last; /* Also if last == NULL */ newtask->next = NULL; + return 0; +} + +int +task_lst_edit_task(TaskLst *list, int i, const char *newstr) +{ + Task *edit; + + if ((edit = task_lst_get_task(*list, i)) == NULL) + return -1; + + strncpy(edit->tdesc, newstr, TASK_LST_DESC_MAX_SIZE); + return 0; } diff --git a/tasklst.h b/tasklst.h index 317454a..b57099b 100644 --- a/tasklst.h +++ b/tasklst.h @@ -28,6 +28,7 @@ int task_lst_count_todo(TaskLst list); int task_lst_count_done(TaskLst list); Task *task_lst_get_task(TaskLst list, int i); int task_lst_add_task(TaskLst *list, int status, const char *str); +int task_lst_edit_task(TaskLst *list, int i, const char *newstr); int task_lst_del_task(TaskLst *list, int i); int task_lst_read_from_file(TaskLst *list, FILE *fp); void task_lst_write_to_file(FILE *fp, TaskLst list); -- cgit v1.2.3