我的目标是建立一个登录系统到我的操作系统。我试图检查两个值(用户名和密码)是否正确。我用的是
int login(char user, char pass, char userCorrect (int))
{
if (user == "admin" && pass == "InHome123")
{
userCorrect = 1;
printf(userCorrect);
return userCorrect;
}
else
{
userCorrect = 0;
printf(userCorrect);
return userCorrect;
}
}为了获得用户输入和调用登录功能,我尝试了
char username[255];
char password[255];
int userCorrect = 0;
...
do
{
printf("| Lixt OS |\n");
printf("Username: ");
memset(username, 0, sizeof(username));
getstr_bound(username, strlen(shell));
printf(username);
printf("Password: ");
memset(password, 0, sizeof(password));
getstr_bound(password, strlen(shell));
printf(password);
printf("\n\n\n\n\n\n");
login(username, password, userCorrect);
}
while(userCorrect == 0);当我运行我的操作系统时,我得到:ScreenShot1
最后那是什么S?我是在声明我的函数,还是说它错了?
发布于 2022-06-19 18:41:17
所以,使用strcmp(var,correct_answer)
void NewSudo(char* b, int* sudo (int))
{
// Vars
char rootName;
char rootPass;
printf("Root Username: ");
memset(rootName, 0, sizeof(rootName));
getstr_bound(rootName, strlen(rootName));
printf("\n");
printf("Root Password: ");
memset(rootPass, 0, sizeof(rootPass));
getstr_bound(rootPass, strlen(rootPass));
printf("\n");
printf("\n\nConfirm authentication:\nRoot Name: %s\nRoot Pass: %s\n", rootName, rootPass);
if (strcmp(rootName, "luis") == 0 && strcmp(rootPass, "pipoca"))
{
printf("Login Correct, SuperUser Loged-in\n");
sudo = 1;
return sudo;
} else {
printf("Login Failed\n");
return sudo;
}
}然后做一次抽筋的动作:
int strcmp(const char *s1, char *s2) {
int i = 0;
while ((s1[i] == s2[i])) {
if (s2[i++] == 0)
return 0;
}
return 1;
}```
And put your func into your header filehttps://stackoverflow.com/questions/70327885
复制相似问题