0

I want to make login code, i use struct for the user and password(still learning) if the user name or password is wrong how to make the function reload again... im confused..

struct user_info {
    int id_num;
    int password;
};

struct user_info user[16];

int load_user_info() {
user[0].id_num = 10; user[0].password = 1004;
user[1].id_num = 20; user[1].password = 2004;

return 0;}

check login code:

int check_login(int id, int passwd) {

    int idd = id;
    int iddd;
    int passs;
    int i;
    int j;


printf("id_num : ");
scanf("%d", &id);
printf("password: ");
scanf("%d", &passwd);


    for (i = 0; i < 17; i++)
    {
        if (idd == user[i].id_num)
        {
            iddd = i;
            break;
        }
        else if ( i == 16 )
        {
            printf("해당 아이디가 없습니다. 다시 로그인 하세요\n");
            return -1;
        }
    }

    for (j = 0; j < 17; j++)
    {
        passs = 0;
        if (passwd == user[j].password)
        {
            passs = j;
            printf("%d\n", j);
            return id;

        }
        else if (j == 16)
        {
            printf("파스워드가 다릅니다. 다지 로그인 하세요\n");
            return -1;
        }
    }
}
1

1 Answer 1

1

Just return 0 if it works properly, otherwise return an error code (for example -1 as you did).

Then:

int return_value = check_login(id, pass);

while (return_value) {
    //here you can change id and pass values
    return_value = check_login(id, pass);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Did you add the return 0?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.