请用c语言写一份学生登录系统,
时间: 2023-06-01 09:07:41 浏览: 55
没问题,以下是一个简单的学生登录系统的C代码实现:
```
#include <stdio.h>
#include <string.h>
struct student {
char name[50];
char id[20];
char password[20];
};
int main() {
struct student stu;
char id_input[20];
char password_input[20];
printf("请输入学号:");
scanf("%s", id_input);
printf("请输入密码:");
scanf("%s", password_input);
FILE *file = fopen("student.txt", "r");
if (file == NULL) {
printf("打开文件失败!\n");
return -1;
}
while (fread(&stu, sizeof(struct student), 1, file)) {
if (strcmp(stu.id, id_input) == 0 && strcmp(stu.password, password_input) == 0) {
printf("欢迎,%s!\n", stu.name);
fclose(file);
return 0;
}
}
printf("学号或密码错误!\n");
fclose(file);
return -1;
}
```
这个程序会让用户输入学号和密码,然后从一个文件中读取所有学生的信息(包括姓名、学号和密码),查找用户输入的学号和密码是否匹配。如果匹配成功,则输出欢迎信息;否则输出错误信息。请注意,这个程序只是一个简单的示例,实际使用时需要更加完善的输入验证和错误处理机制。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)