Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

create todo app using c

  1. User

    create todo app using c

  2. Assistant

    To create a todo app using C, you can follow the steps below:

    1. Start by creating a new C file (.c) in your preferred text editor.

    2. Include necessary header files for input/output and string manipulation:

      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      
    3. Define a structure to represent a todo task. The structure should include variables for task details such as task name, description, and status:

      typedef struct {
          char name[100];
          char description[200];
          int status;
      } Task;
      
    4. Write a function to display the menu options and prompt the user for their choice:

      void displayMenu() {
          printf("TODO APP\n");
          printf("1. Add Task\n");
          printf("2. Display All Tasks\n");
          printf("3. Mark Task as Complete\n");
          printf("4. Exit\n");
          printf("Enter your choice: ");
      }
      
    5. Write a function to add a new task to the todo list:

      void addTask(Task *tasks, int *count) {
          printf("Enter task name: ");
          scanf("%s", tasks[*count].name);
      
          printf("Enter task description: ");
          scanf("%s", tasks[*count].description);
      
          tasks[*count].status = 0;
          (*count)++;
      }
      
    6. Write a function to display all the tasks in the todo list:

      void displayTasks(Task *tasks, int count) {
          if (count == 0) {
              printf("No tasks found.\n");
          } else {
              for (int i = 0; i < count; i++) {
                  printf("Task %d:\n", i+1);
                  printf("Name: %s\n", tasks[i].name);
                  printf("Description: %s\n", tasks[i].description);
                  printf("Status: %s\n", tasks[i].status == 0 ? "Incomplete" : "Complete");
                  printf("\n");
              }
          }
      }
      
    7. Write a function to mark a task as complete:

      void markComplete(Task *tasks, int count) {
          int taskNumber;
          printf("Enter task number to mark as complete: ");
          scanf("%d", &taskNumber);
      
          if (taskNumber > 0 && taskNumber <= count) {
              tasks[taskNumber-1].status = 1;
              printf("Task marked as complete.\n");
          } else {
              printf("Invalid task number.\n");
          }
      }
      
    8. In the main function, create an array of tasks and a count variable to keep track of the number of tasks:

      int main() {
          Task tasks[100];
          int count = 0;
          int choice;
      
          do {
              displayMenu();
              scanf("%d", &choice);
      
              switch (choice) {
                  case 1:
                      addTask(tasks, &count);
                      break;
                  case 2:
                      displayTasks(tasks, count);
                      break;
                  case 3:
                      markComplete(tasks, count);
                      break;
                  case 4:
                      printf("Exiting...\n");
                      break;
                  default:
                      printf("Invalid choice. Please try again.\n");
              }
      
          } while (choice != 4);
      
          return 0;
      }
      
    9. Compile the program and run it. You can add tasks, display all tasks, mark tasks as complete, and exit the app as per your choice.

    Note: While this is a basic implementation of a todo app in C, you can modify and enhance it further based on your requirements.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.