首页 > 解决方案 > 我正在尝试使用 C 编程语言创建登录系统

问题描述

我正在尝试使用 C 编程语言创建登录系统。下面的代码是我的尝试,谁能指出我的错误。目标是匹配程序中的用户名和密码。例如,如果我输入 Amy 作为用户名和 Amy76 作为密码应该接受它并打印登录。

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

标签: c

解决方案


您不能将 0 返回给返回 void 的函数。

请提及您从此代码中得到的错误。


推荐阅读