I'm trying to take inputs from user about their login credentials (username and password) and then checking whether the username and password are valid or not.
#include <stdio.h>
int main()
{
    printf("-----------------------------------");
    printf("-----------REGISTER----------------");
    char username[10], pwd[6];
    char check_usn[10], check_pwd[6];
    printf("\nEnter your username\n");
    scanf("%s", username);
    printf("Enter your password (length should be 6\n");
    scanf("%s", pwd);
    printf("-----------------------------------");
    printf("-------------LOG IN--------------");
    printf("\nEnter your username\n");
    scanf("%s", check_usn);
    printf("Enter your password (length should be 6\n");
    scanf("%s", check_pwd);
    int i = 0, key = 0;
    while(i<(sizeof(username)/sizeof(username[0])))
    {
        if(username[i] == check_usn)
        {
            key = i;
        }
        else
        {
            i++;
        }
    }
    if(pwd[key] == check_pwd)
    {
        printf("Valid password");
    }
    else
    {
        printf("Wrong password");
    }
    return 0;
}
Warning : comparison between pointer and integer And also I'm getting the wrong output.
I tried this now and now I'm getting segmentation fault.
#include <stdio.h>
#include <string.h>
int main()
{
    printf("-----------------------------------");
    printf("-----------REGISTER----------------");
    char username[10], pwd[6];
    char check_usn[10], check_pwd[6];
    printf("\nEnter your username\n");
    scanf("%s", username);
    printf("Enter your password (length should be 6\n");
    scanf("%s", pwd);
    printf("-----------------------------------");
    printf("-------------LOG IN--------------");
    printf("\nEnter your username\n");
    scanf("%s", check_usn);
    printf("Enter your password (length should be 6\n");
    scanf("%s", check_pwd);
    int i = 0, key = 0;
    while(i<(sizeof(username)/sizeof(username[0])))
    {
        if(strcmp(username[i],check_usn) == 0)
        {
            key = i;
        }
        else
        {
            i++;
        }
    }
    if(strcmp(pwd[key],check_pwd) == 0)
    {
        printf("Valid password");
    }
    else
    {
        printf("Wrong password");
    }
    return 0;
}
 
     
     
    