【问题标题】:C Password Log giving me errorsC密码日志给我错误
【发布时间】:2015-10-03 13:59:30
【问题描述】:

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);
}

【问题讨论】:

  • 报错信息明明跟passwd函数没有关系,那你的问题是为什么呢?并发布实际失败的代码——这不会,因为你已经注释掉了错误的代码——并在错误消息中包含行号和/或在你发布的代码中清楚地标记有问题的行。跨度>

标签: c passwords c-strings


【解决方案1】:

\uprintf中的特殊代码;您的代码包含 \username 导致您遇到的错误。我怀疑你只是有一个错字;如果不是,则在printf 中用\\ 表示反斜杠。

根据@Jim Balter 的评论,您可能使用了\,您的意思是/

【讨论】:

  • OP 想要一个正斜杠——“密码/用户名不正确”
猜你喜欢
  • 1970-01-01
  • 2014-11-22
  • 2012-12-11
  • 2015-12-11
  • 2017-08-17
  • 2013-06-30
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
相关资源
最近更新 更多