-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathipop.c
55 lines (47 loc) · 1.1 KB
/
ipop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#ifndef TASK
#include "Task.c"
#endif
#define filename "__SavedTasks.txt"
void writeTodoListToFile()
{
FILE *fp = fopen(filename, "w+");
if (fp == NULL)
{
printf("File Created !\n");
return;
}
Task *temp = head;
while (temp != NULL)
{
fprintf(fp, "%d. %s-%d\n", temp->taskNumber, temp->description, temp->isCompleted);
temp = temp->next;
}
fclose(fp);
}
void readTodoListFromFile()
{
FILE *fp = fopen(filename, "r+");
if (fp == NULL)
{
printf("File Created !\n");
return;
}
head = NULL;
Task *ptr = NULL;
Task *tail = NULL;
char line[100];
while (fgets(line, 100, fp) != NULL)
{
int taskNumber;
char description[100];
int isCompleted;
sscanf(line, "%d. %[^-]-%d", &taskNumber, description, &isCompleted);
addTask(taskNumber, description, isCompleted);
}
fclose(fp);
}
void printNode(Task *node)
{
printf("ID: %d ___ \n %s\n -> %s\n__\n", node->taskNumber, node->description, node->isCompleted == 0 ? "PENDING" : "COMPLETED");
}