C密码功能不起作用。我不知道出了什么问题。有人可以帮忙吗?
Error: Incomplete universal character \u
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
void userLog(int attempt, char user_name[], char user_pass[]);
void checkUserLog(int attempt, char user_name[], char user_pass[]);
int main()
{
system("color 1F"); //change UI background to blue and text to white
int *pos = 0;
int attempt = 0;
int low, high, *temp_pos;
char searchKey[50], *is_found[200];
char user_name[6], user_pass[12];
//printf("print main's test\n\n");
userLog(attempt, user_name, user_pass);
//libraryBookMainMenu(searchKey[50], low, high, &is_found[200], &temp_pos);
//systemMainMenu();
fflush(stdin);
getch();
}
void userLog(int attempt, char user_name[], char user_pass[])
{
system("cls");
if (attempt == 0) {
printf("Access is Denied!!!");
Sleep(1500);
attempt = 3; //done to reset attempts for user login
exit(2);
}
attempt--;
printf("\n\n Enter your username: ");
fflush(stdin); // done to clear last input after the while statement is not true
scanf("%s", &user_name);
printf("\n\n Enter your password: ");
fflush(stdin); // done to clear last input after the while statement is not true
checkUserLog(attempt, user_name, user_pass);
}
void checkUserLog(int attempt, char user_name[], char user_pass[])
{
int i = 0;
char get_char;
char default_user[] = "admin";
char default_pass[] = "adminpass00";
while (i < 10) {
get_char = getch();
if (get_char == 13) {
break; //ASCII value for enter
}
if (get_char == 8) {
putch('\b'); //escape sequence for backspace
putch(' '); //puts an empty space as you backspace
putch('\b'); //return blinking cursor to original position
i--;
continue; //without this backspace won't work
}
user_pass[i] = get_char;
printf("*");
i++;
}
user_pass[i] = '\0';
/*while (strcmp(user_name,default_user)!= 0 || strcmp(user_pass,default_pass) != 0) {
printf("\n Incorrect password\username\n\n\t %d more attempts remaining", attempt);
Sleep(1500);
userLog(attempt, user_name, user_pass);
}*/
attempt = 3;
//libraryBookMainMenu(bookLibrary, searchKey[50], low, high, &pos, &temp_pos);
}
答案 0 :(得分:0)
\u
是printf
中的特殊代码;您的代码包含\username
,这会导致您获得错误。我怀疑你那里有一个错字;如果不是,则使用printf
代表\\
中的反斜杠。
根据@Jim Balter的评论,您可能使用\
表示/
。