多端内容管理接口自动化测试部署清单
```c struct User { char username[50]; char password[50]; }; ``` 全局变量 在程序中维护一个用户数组,用于存储注册的用户: ```c struct User users[100]; // 最多支持 100 个用户 int num_users = 0; // 当前用户数量 ``` 注册函数 该函数允许用户创建一个新帐户: ```c void register_user() { struct User new_user; printf("Enter username: "); scanf("%s", new_user.username); printf("Enter password: "); scanf("%s", new_user.password); // 检查用户名是否已存在 for (int i = 0; i if (strcmp(new_user.username, users[i].username) == 0) { printf("Username already exists.\n"); return; } } // 添加新用户到数组 users[num_users++] = new_user; printf("Registration successful.\n"); } ``` 登录函数 该函数允许用户使用现有的帐户登录: ```c void login_user() { char username[50]; char password[50]; printf("Enter username: "); scanf("%s", username); printf("Enter password: "); scanf("%s", password); // 查找匹配的用户名和密码 for (int i = 0; i if (strcmp(username, users[i].username) == 0 && strcmp(password, users[i].password) == 0) { printf("Login successful.\n"); return; } } // 如果没有找到匹配项,则打印错误消息 printf("Invalid username or password.\n"); } ``` 主函数 在主函数中,用户可以选择注册或登录: ```c int main() { int choice; while (1) { printf(" Register\n Login\n Exit\nEnter your choice: "); scanf("%d", &choice); switch (choice) { case 1: register_user(); break; case 2: login_user(); break; case 3: exit(0); default: printf("Invalid choice.\n"); } } return 0; } ``` 示例输出 注册 ``` Enter username: John Enter password: password123 Registration successful. ``` 登录 ``` Enter username: John Enter password: password123 Login successful. ```