我正在尝试使用C编程语言创建登录系统。以下代码是我的尝试,任何人都可以向我指出我的错误。目标是匹配程序中的用户名和密码。例如,如果我要以用户名和amy76的方式输入Amy,则应接受密码并打印登录。
#include<conio.h>
#include<string.h>
int main()
{
login_session();
return 0;
}
// following function accepts the login creed for teachers
void login_session(char username[10], char password[10]){
printf("Enter instructor's Full Name :n");
scanf("%s", &username);
printf("Enter password :n");
scanf("%s", &password);
clrscr();
//conditional statements to test teachers username and password
if(strcmp(username, "Amy") ==0) {
if(strcmp(password,"Amy76") ==0){
printf("nwelcome. Login Sucessfully ");
} else {
printf("ninvalid. username and password does not exist");
}
} else if (strcmp(username, "Smith") ==0){
if(strcmp(password,"Smith345") ==0){
printf("nwelcome. Login Sucessfully");
} else {
printf("ninvalid.username and password does not exist");
}
} else if (strcmp(username, "Doris") ==0) {
if(strcmp(password,"Doris284") ==0){
printf("nwelcome.Login Sucessfully");
}else {
printf("ninvalid. username and password does not exist");
}
} else if (strcmp(username,"Wilson") == 0) {
if(strcmp(password,"Wilson809") ==0){
printf("nwelcome.Login Sucessfully");
}else {
printf("ninvalid. username and password does not exist");
}
}
return 0;
}
您无法返回0返回void的函数。
请提及错误您是从此代码中获得的。
我解决了问题
我意识到我返回0到一个无效的函数并整理我的括号我意识到我需要一个两个char阵列示例
而不是这样:
void login_session(char username[10], char password[10]){ //ect }
我尝试了:
void login_session(){
char username[10];
char password[10];
}