whycxsa 2022-06-04 23:11 采纳率: 82.8%
浏览 827
已结题

比较用户键盘输入的口令userInput与内设的口令password是否相同

比较用户键盘输入的口令userInput与内设的口令password是否相同


#include <stdio.h>
#include <string.h>
int main()
{
    char password[7] = "secret";    
    char userInput[81] ;
    printf("Input Password:");
    scanf(_____________);//第8行
    if ( ______________ )//第9行
        printf("Correct password! Welcome to the system...\n");
    else if ( ___________________) //第11行
   
        printf("Invalid password!user input<password\n");
    else
        printf("Invalid password!user input>password\n");   
    return 0;
}

能给个大致思路吗?谢谢!

  • 写回答

1条回答 默认 最新

  • Hann Yang 全栈领域优质创作者 2022-06-05 00:48
    关注
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        char password[7] = "secret";    
        char userInput[81] ;
        printf("Input Password:");
        scanf("%s", userInput);//第8行
        if ( strcmp(userInput,password)==0 )//第9行
            printf("Correct password! Welcome to the system...\n");
        else if ( strcmp(userInput,password)<0 ) //第11行
            printf("Invalid password!user input<password\n");
        else
            printf("Invalid password!user input>password\n");   
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月13日
  • 已采纳回答 6月5日
  • 创建了问题 6月4日