Skip to content

Commit

Permalink
fixed bugs in saved file
Browse files Browse the repository at this point in the history
  • Loading branch information
pheeya committed Jun 7, 2023
1 parent cb7886d commit b5905c0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
11 changes: 7 additions & 4 deletions Task.C
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ Task *ReadTasks(const char *_filePath, int *num)
char delim[] = " ";
while (fgets(line, MAX_LINE_LENGTH, file) != NULL)
{
line[strcspn(line, "\n")] = 0;
char *token = strtok(line, delim);
char desc[MAX_LINE_LENGTH] = "";
const char *val;

while (token != NULL)
{
val = token;
if (val != "0" && val != "1")
if (*val != '0' && *val != '1')
{
strcat(desc, token);
strcat(desc, " ");
Expand All @@ -86,7 +87,6 @@ Task *ReadTasks(const char *_filePath, int *num)
token = strtok(NULL, delim);
}
bool completed = *val == '1';

AddTask(&tasks, num, desc, completed);
}

Expand Down Expand Up @@ -209,7 +209,7 @@ void OverrideDailyTask(int _index, int _completed)
{
DailyTasks[_index].completed = _completed;
FRAME_DIRTY = true;
UpdateTaskInFile("Daily.txt", td_selected, &DailyTasks[td_selected]);
UpdateTaskInFile("Daily.txt", _index, &DailyTasks[_index]);
}

void UpdateTaskInFile(const char *_filePath, int _taskNum, Task *_task)
Expand All @@ -230,7 +230,10 @@ void UpdateTaskInFile(const char *_filePath, int _taskNum, Task *_task)
strcpy(newLine, _task->description);
strcat(newLine, " ");
strcat(newLine, _task->completed ? "1" : "0");
strcat(newLine, "\n");
if (_taskNum != td_num_daily_tasks - 1)
{
strcat(newLine, "\n");
}

while (fgets(line, MAX_LINE_LENGTH, file) != NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
gcc -mwindows main.c renderer.c events/events.c Task.c events/keyboard/keyboardEvent.c context.c -luser32 -lgdi32 -o rtodo.exe && rtodo.exe
gcc main.c renderer.c events/events.c Task.c events/keyboard/keyboardEvent.c context.c -luser32 -lgdi32 -o rtodo.exe && rtodo.exe
10 changes: 5 additions & 5 deletions daily.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fin 1
cyclosporin 1
cyclosporin 1
cyclosporin 0
tobramycin (ointment) 0
fin 1
cyclosporin 1
cyclosporin 0
cyclosporin 0
tobramycin (ointment) 0
2 changes: 1 addition & 1 deletion last-updated.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3
4
Binary file modified rtodo.exe
Binary file not shown.

0 comments on commit b5905c0

Please sign in to comment.