0% found this document useful (0 votes)
9 views

Advanced Coding Assignment-6(0404)

The document presents a C program for a routine management system that allows users to add, view, and delete tasks. It defines a structure for tasks and implements functions for each operation, along with a menu-driven interface for user interaction. The program ensures task management with a limit on the number of tasks and provides feedback for each action performed.

Uploaded by

sohan kamsani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Advanced Coding Assignment-6(0404)

The document presents a C program for a routine management system that allows users to add, view, and delete tasks. It defines a structure for tasks and implements functions for each operation, along with a menu-driven interface for user interaction. The program ensures task management with a limit on the number of tasks and provides feedback for each action performed.

Uploaded by

sohan kamsani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ADVANCED CODING ASSIGNMENT -6

K CHANDRASEKHAR
VU21CSEN0100404
6. Write a program to implement routine
management system using C.
#CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_TASKS 100


#define MAX_LENGTH 100

struct Task {
int id;
char description[MAX_LENGTH];
};

void addTask(struct Task tasks[], int *taskCount);


void viewTasks(struct Task tasks[], int taskCount);
void deleteTask(struct Task tasks[], int *taskCount);

int main() {
struct Task tasks[MAX_TASKS];
int taskCount = 0;
int choice;

while (1) {
// Display menu
printf("\n=== Routine Management System ===\n");
printf("1. Add Task\n");
printf("2. View All Tasks\n");
printf("3. Delete Task\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
getchar();

// Handle user choice


switch (choice) {
case 1:
addTask(tasks, &taskCount);
break;
case 2:
viewTasks(tasks, taskCount);
break;
case 3:
deleteTask(tasks, &taskCount);
break;
case 4:
printf("Exiting...\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
}
}

return 0;
}

void addTask(struct Task tasks[], int *taskCount) {


if (*taskCount >= MAX_TASKS) {
printf("Error: Task list is full.\n");
return;
}

struct Task newTask;


newTask.id = *taskCount + 1;
printf("Enter the description of the task: ");
fgets(newTask.description, MAX_LENGTH, stdin);
newTask.description[strcspn(newTask.description, "\n")] = 0;

tasks[*taskCount] = newTask;
(*taskCount)++;
printf("Task added successfully.\n");
}

void viewTasks(struct Task tasks[], int taskCount) {


if (taskCount == 0) {
printf("No tasks available.\n");
return;
}

printf("\n--- All Tasks ---\n");


for (int i = 0; i < taskCount; i++) {
printf("Task ID: %d\n", tasks[i].id);
printf("Description: %s\n\n", tasks[i].description);
}
}

void deleteTask(struct Task tasks[], int *taskCount) {


if (*taskCount == 0) {
printf("No tasks to delete.\n");
return;
}

int id;
printf("Enter the task ID to delete: ");
scanf("%d", &id);
getchar();

int found = 0;
for (int i = 0; i < *taskCount; i++) {
if (tasks[i].id == id) {
found = 1;

for (int j = i; j < *taskCount - 1; j++) {


tasks[j] = tasks[j + 1];
}
(*taskCount)--;
printf("Task deleted successfully.\n");
break;
}
}

if (!found) {
printf("Task ID %d not found.\n", id);
}
}
OUTPUT:

You might also like