程序设计停车场管理系统普通用户管理层用户c语言
时间: 2023-07-13 09:04:14 浏览: 79
以下是一个简单的停车场管理系统的普通用户管理层用户的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_USERS 100
#define MAX_NAME_LENGTH 20
#define MAX_PASSWORD_LENGTH 20
struct User {
char name[MAX_NAME_LENGTH];
char password[MAX_PASSWORD_LENGTH];
};
struct User users[MAX_USERS];
int num_users = 0;
void register_user() {
if (num_users >= MAX_USERS) {
printf("ERROR: Maximum number of users reached.\n");
return;
}
struct User user;
printf("Enter your name: ");
scanf("%s", user.name);
printf("Enter your password: ");
scanf("%s", user.password);
users[num_users] = user;
num_users++;
printf("User registered successfully.\n");
}
void login() {
char name[MAX_NAME_LENGTH];
char password[MAX_PASSWORD_LENGTH];
printf("Enter your name: ");
scanf("%s", name);
printf("Enter your password: ");
scanf("%s", password);
for (int i = 0; i < num_users; i++) {
if (strcmp(users[i].name, name) == 0 && strcmp(users[i].password, password) == 0) {
printf("Login successful.\n");
return;
}
}
printf("ERROR: Invalid name or password.\n");
}
int main() {
int choice;
while (1) {
printf("1. Register\n");
printf("2. Login\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
register_user();
break;
case 2:
login();
break;
case 3:
exit(0);
default:
printf("Invalid choice.\n");
}
}
return 0;
}
```
此代码实现了两个功能:用户注册和用户登录。每个用户都有一个名字和密码,这些信息存储在 `users` 数组中。程序可以处理最多100个用户。用户可以通过输入他们的名字和密码进行登录。如果登录成功,程序将打印“登录成功”,否则将打印“无效的用户名或密码”。
阅读全文