add csv export

This commit is contained in:
2025-12-22 04:03:26 +01:00
parent 6862af407e
commit e97e106001
3 changed files with 34 additions and 1 deletions

View File

@@ -55,3 +55,20 @@ char *todo_item_serialize(TodoItem *item, int *buffer_size_out) {
return buffer;
}
// Exports
void todo_export_as_csv(TodoItem *items, int item_count, const char *filename) {
FILE *file = fopen(filename, "w");
if (file == NULL) {
perror("Failed to open file for writing");
return;
}
// Write CSV header
fprintf(file, "Title,Completed\n");
for (int i = 0; i < item_count; i++) {
fprintf(file, "\"%s\",%s\n", items[i].title,
items[i].completed ? "Yes" : "No");
}
fclose(file);
}

View File

@@ -20,4 +20,7 @@ void todo_print_item(TodoItem *item);
// Serialization
char *todo_item_serialize(TodoItem *item, int *buffer_size_out);
// Exports
void todo_export_as_csv(TodoItem *items, int item_count, const char *filename);
#endif