-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtodo.c
More file actions
312 lines (257 loc) · 5.42 KB
/
todo.c
File metadata and controls
312 lines (257 loc) · 5.42 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// C program for the above approach
#include <stdio.h>
#include <stdlib.h>
// Renaming structure to avoid the
// repetitive use of struct keyword
typedef struct ToDo todo;
// Declaration of structure
struct ToDo {
// char array as data part
char buffer[101];
// Pointer part to access addresses
todo* next;
// Count variable for counting
// the number of nodes
int count;
};
// Declare start pointer as null in
// the beginning
todo* start = NULL;
// Driver Code
int main()
{
int choice;
interface();
while (1) {
// Change console color and
// text color
system("Color 3F");
// Clear the console
system("cls");
printf("1. To see your ToDo list\n");
printf("2. To create new ToDo\n");
printf("3. To delete your ToDo\n");
printf("4. Exit");
printf("\n\n\nEnter your choice\t:\t");
// Choice from the user
scanf("%d", &choice);
switch (choice) {
// Calling functions defined
// below as per the user input
case 1:
seetodo();
break;
case 2:
createtodo();
break;
case 3:
deletetodo();
break;
case 4:
exit(1);
break;
default:
printf("\nInvalid Choice :-(\n");
system("pause");
}
}
return 0;
}
// Code for Splash screen
void interface()
{
system("color 4F");
printf("\n\n\n\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~\n\n");
printf("\t} : } : } : } : } : } "
": } : } : } : "
"WELCOME TO the TODO APP "
" : { : { : { : { : { "
": { : { : { : {\n\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~~~~~~~~~~~~~~~"
"~~~~~~~~~~\n");
printf("\n\n\n\t\t\t\t\t\t\t\"
"t\t\t\t "
"@Sushant_Gaurav\n\n\n\n"
"\n\n\n\t");
// Pausing screen until user
// presses any key
system("pause");
}
// To view all the todos
void seetodo()
{
// Clearing the console
system("cls");
// Pointer to the node for traversal
todo* temp;
// temp is made to point the
// start of linked list
temp = start;
// Condition for empty linked list
if (start == NULL)
printf("\n\nEmpty ToDo \n\n");
// Traverse until last node
while (temp != NULL) {
// Print number of the node
printf("%d.)", temp->count);
// Print data of the node
puts(temp->buffer);
// Clear output console
fflush(stdin);
// Going to next node
temp = temp->next;
}
printf("\n\n\n");
system("pause");
}
// Function to insert a node todo
void createtodo()
{
// Choose choice from user
char c;
// Pointers to node
todo *add, *temp;
system("cls");
// Infinite loop which will
// break if "n" is pressed
while (1) {
printf("\nWant to add new ToDo ??"
+ " Press 'y' for Yes and 'n' "
+ " for No :-)\n\t\t");
fflush(stdin);
// Input from user
scanf("%c", &c);
if (c == 'n')
break;
else {
// If start node is NULL
if (start == NULL) {
// Dynamically allocating
// memory to the newly
// created node
add = (todo*)calloc(1, sizeof(todo));
// Using add pointer to
// create linked list
start = add;
printf("\nType it.....\n");
// Input from user
fflush(stdin);
gets(add->buffer);
// As first input so
// count is 1
add->count = 1;
// As first node so
// start's next is NULL
start->next = NULL;
}
else {
temp = (todo*)calloc(1, sizeof(todo));
printf("\nType it.....\n");
fflush(stdin);
gets(temp->buffer);
// Insertion is at last
// so pointer part is NULL
temp->next = NULL;
// add is now pointing
// newly created node
add->next = temp;
add = add->next;
}
// Using the concept of
// insertion at the end,
// adding a todo
// Calling function to adjust
// the count variable
adjustcount();
}
}
}
// Function to delete the todo
void deletetodo()
{
system("cls");
// To get the numbering of the
// todo to be deleted
int x;
todo *del, *temp;
printf("\nEnter the ToDo's number"
+ " that you want to remove.\n\t\t");
// Checking empty condition
if (start == NULL)
printf("\n\nThere is no ToDo"
+ " for today :-)\n\n\n");
else {
scanf("%d", &x);
// del will point to start
del = start;
// temp will point to start's
// next so that traversal and
// deletion is achieved easily
temp = start->next;
// Running infinite loop so
// that user can delete and
// asked again for choice
while (1) {
// When the values matches,
// delete the node
if (del->count == x) {
// When the node to be
// deleted is first node
start = start->next;
// Deallocating the memory
// of the deleted node
free(del);
// Adjusting the count when
// node is deleted
adjustcount();
break;
}
if (temp->count == x) {
del->next = temp->next;
free(temp);
adjustcount();
break;
}
else {
del = temp;
temp = temp->next;
}
}
}
system("pause");
}
// Function to adjust the numbering
// of the nodes
void adjustcount()
{
// For traversal, using
// a node pointer
todo* temp;
int i = 1;
temp = start;
// Running loop until last node
// and numbering it one by one
while (temp != NULL) {
temp->count = i;
i++;
temp = temp->next;
}
}