forked from sujan-poudel-03/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ffd9b6
commit 6bf5316
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define MAX_SIZE 100 | ||
|
||
struct ToDoList { | ||
char tasks[MAX_SIZE][100]; | ||
int size; | ||
}; | ||
|
||
void initList(struct ToDoList* list) { | ||
list->size = 0; | ||
} | ||
|
||
void addTask(struct ToDoList* list, char task[]) { | ||
if (list->size == MAX_SIZE) { | ||
printf("List is full! Cannot add more tasks.\n"); | ||
return; | ||
} | ||
|
||
strcpy(list->tasks[list->size], task); | ||
list->size++; | ||
} | ||
|
||
void displayTasks(struct ToDoList* list) { | ||
if (list->size == 0) { | ||
printf("No tasks in the list.\n"); | ||
return; | ||
} | ||
|
||
printf("Tasks:\n"); | ||
for (int i = 0; i < list->size; i++) { | ||
printf("%d. %s\n", i + 1, list->tasks[i]); | ||
} | ||
} | ||
|
||
int main() { | ||
struct ToDoList myToDoList; | ||
initList(&myToDoList); | ||
|
||
addTask(&myToDoList, "Buy groceries"); | ||
addTask(&myToDoList, "Pay bills"); | ||
addTask(&myToDoList, "Do laundry"); | ||
|
||
displayTasks(&myToDoList); | ||
|
||
return 0; | ||
} |