用c语言写一个学生信息登陆程序
时间: 2023-05-11 13:07:18 浏览: 50
好的,以下是一个简单的学生信息登陆程序的 C 语言代码:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Student {
char name[50];
char id[20];
char password[20];
};
int main() {
struct Student students[MAX_STUDENTS];
int num_students = 0;
// 添加学生信息
strcpy(students[num_students].name, "张三");
strcpy(students[num_students].id, "20190101");
strcpy(students[num_students].password, "123456");
num_students++;
strcpy(students[num_students].name, "李四");
strcpy(students[num_students].id, "20190102");
strcpy(students[num_students].password, "abcdef");
num_students++;
// 登陆
char id[20], password[20];
printf("请输入学号:");
scanf("%s", id);
printf("请输入密码:");
scanf("%s", password);
int i;
for (i = 0; i < num_students; i++) {
if (strcmp(students[i].id, id) == 0 && strcmp(students[i].password, password) == 0) {
printf("欢迎,%s!\n", students[i].name);
return 0;
}
}
printf("登陆失败!\n");
return 1;
}
```
这个程序可以添加多个学生信息,然后让用户输入学号和密码进行登陆验证。如果验证成功,就输出欢迎信息,否则输出登陆失败。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)