add csv export
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user