STM32实现简单的智能办公系统

时间:2024-10-08 07:02:18
  • #define MAX_TASKS 100
  • typedef struct {
  • char title[100];
  • char description[1000];
  • char deadline[20];
  • } Task;
  • Task tasks[MAX_TASKS];
  • int taskCount = 0;
  • void createTask(char *title, char *description, char *deadline) {
  • // 创建新任务
  • Task newTask;
  • strncpy(, title, sizeof());
  • strncpy(, description, sizeof());
  • strncpy(, deadline, sizeof());
  • tasks[taskCount++] = newTask;
  • printf("Task created successfully!\n");
  • }
  • void updateTask(int taskIndex, char *title, char *description, char *deadline) {
  • if (taskIndex < 0 || taskIndex >= taskCount) {
  • printf("Invalid task index!\n");
  • return;
  • }
  • // 更新任务信息
  • Task *task = &tasks[taskIndex];
  • strncpy(task->title, title, sizeof(task->title));
  • strncpy(task->description, description, sizeof(task->description));
  • strncpy(task->deadline, deadline, sizeof(task->deadline));
  • printf("Task updated successfully!\n");
  • }
  • void deleteTask(int taskIndex) {
  • if (taskIndex < 0 || taskIndex >= taskCount) {
  • printf("Invalid task index!\n");
  • return;
  • }
  • // 删除任务
  • for (int i = taskIndex; i < taskCount - 1; i++) {
  • tasks[i] = tasks[i + 1];
  • }
  • taskCount--;
  • printf("Task deleted successfully!\n");
  • }
  • void viewTasks() {
  • for (int i = 0; i < taskCount; i++) {
  • Task *task = &tasks[i];
  • printf("Task %d:\n", i + 1);
  • printf("Title: %s\n", task->title);
  • printf("Description: %s\n", task->description);
  • printf("Deadline: %s\n", task->deadline);
  • printf("\n");
  • }
  • }