-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
184 lines (177 loc) · 7.33 KB
/
Copy pathmain.c
File metadata and controls
184 lines (177 loc) · 7.33 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tasks.h"
int main(){
char name[100];
int isDue = 0;
int comp_task_id, task_prio, sort = 1;
TaskManager manager = {.tail = NULL, .size = 0, .next_id = 1};
printf("Welcome to To-Do List Manager!\n\n");
loadTasks(&manager);
while(1){
printf("------------TASK MANAGER------------");
printf("\n----1. Add a Task to the List!----");
printf("\n----2. Toggle the Completion of a Task (Complete/Incomplete)!----");
printf("\n----3. Remove a Task from the List.----");
printf("\n----4. Edit a Task.----");
printf("\n----5. Print the Task List.----");
printf("\n----6. Empty the List.----");
printf("\n----7. Search the List.----");
printf("\n----8. List Settings.----");
printf("\n----9. Save and Quit Task Manager.----");
printf("\n----10. Quit.----");
printf("\nChoose your action: ");
char buff1[10];
fgets(buff1, sizeof(buff1), stdin);
int choice = atoi(buff1);
switch(choice){
case 1:
printf("Type the name of the Task: ");
fgets(name, sizeof(name), stdin);
name[strcspn(name, "\n")] = '\0'; //remove the newline from the input
printf("What is the Priority of this Task (1 = LOW, 2 = MEDIUM, 3 = HIGH): ");
char buff2[10];
fgets(buff2, sizeof(buff2), stdin);
task_prio = atoi(buff2);
if(task_prio != LOW && task_prio != MEDIUM && task_prio != HIGH){
printf("Wrong Priority input. Try again.");
break;
}
printf("Do you want to enter a due date for this task? (0 = NO, 1 = YES): ");
char buffD[10];
fgets(buffD, sizeof(buffD), stdin);
isDue = atoi(buffD);
int day, month, year;
if(isDue){
printf("Enter the day as a number: ");
char buffd[10];
fgets(buffd, sizeof(buffd), stdin);
day = atoi(buffd);
printf("Enter the month as a number: ");
char buffm[10];
fgets(buffm, sizeof(buffm), stdin);
month = atoi(buffm);
printf("Enter the year as a number: ");
char buffy[10];
fgets(buffy, sizeof(buffy), stdin);
year = atoi(buffy);
}
else{ day = 0, month = 0, year = 0;}
if (addTask(&manager, name, -1, task_prio, day, month, year, 0)){
printf("\nSuccessfully added task %d: %s!", manager.next_id-1, name);
}
else{
printf("\nInvalid Task name, try again.");
}
break;
case 2:
printf("\nType the id of the task you wish to complete/incomplete: ");
char buff3[10];
fgets(buff3, sizeof(buff3), stdin);
comp_task_id = atoi(buff3); //mixing scanf will leave the newline for the fgets next call - leading to unexpected behaviour
if(completeTask(&manager, comp_task_id)){
printf("\nSuccessfully toggled task completion of Task %d!", comp_task_id);
}
else{
printf("\nInvalid Task id, try again.");
}
break;
case 3:
printf("\nType the id of the task you wish to Remove: ");
char buff4[10];
fgets(buff4, sizeof(buff4), stdin);
comp_task_id = atoi(buff4);
if(deleteTask(&manager, comp_task_id)){
printf("\nSuccessfully deleted task %d!", comp_task_id);
}
else{
printf("\nInvalid Task id, try again.");
}
break;
case 4:
printf("Which task would you like to edit: ");
char buff5[10];
fgets(buff5, sizeof(buff5), stdin);
comp_task_id = atoi(buff5);
editTask(&manager, comp_task_id);
break;
case 5:
printList(&manager, sort);
break;
case 6:
freeList(&manager);
printf("List is EMPTY!");
break;
case 7:
while(1){
printf("1. Search by Name?");
printf("\n or");
printf("\n2. Search by ID?\n");
printf("Choice: ");
char buffsearch[10];
fgets(buffsearch, sizeof(buffsearch), stdin);
int search = atoi(buffsearch);
if(search == 1){
printf("Enter the name of the task you wish to find: ");
char buffsearchname[100];
fgets(buffsearchname, sizeof(buffsearchname), stdin);
buffsearchname[strcspn(buffsearchname, "\n")] = '\0';
searchTaskByName(&manager, buffsearchname);
break;
}
else if(search == 2){
printf("Enter the ID of the task you wish to find: ");
char buffsearchid[10];
fgets(buffsearchid, sizeof(buffsearchid), stdin);
searchTaskById(&manager, atoi(buffsearchid));
break;
}
else{
printf("Incorrect option. Try again.\n");
}
}
break;
case 8:
while(1){
printf("1. Sort by Priority\n2. Sort by Completion Status\nYour Choice: ");
char buffsort[10];
fgets(buffsort, sizeof(buffsort), stdin);
sort = atoi(buffsort);
if(sort != 1 && sort != 2){
printf("Incorrect option. Try again.\n");
continue;
}
break;
}
break;
case 9:
saveTasks(&manager);
printf("Thanks for using us!\n");
exit(1);
break;
case 10:
int quit = 0;
while(1){
printf("Are you sure you want to quit without saving?\n(1 = Yes, 2 = No): ");
char buffquitid[10];
fgets(buffquitid, sizeof(buffquitid), stdin);
quit = atoi(buffquitid);
if(quit == 1){
printf("Thanks for using us!\n");
exit(1);
}
else if(quit == 2){
saveTasks(&manager);
printf("Thanks for using us!\n");
exit(1);
}
printf("Wrong input. ");
}
default:
printf("Make a choice or Quit!");
break;
}
printf("\n");
}
}