[Solved] so i try to create my simple register and login using c [closed]


As you use username and password of type char, you can’t read them by %s (for strings) in the scanf function, use %c (for chars) instead.

If your username and password contain more than 1 char, use a char array. For example char username [20]. Now you can fill them in the scanf function with the parameter %s. To compare them use the function strcmp() (Keep in mind that you have to include string.h)

A possible solution in your case could be:

main(){
char username[20];
int password;
printf("Enter your username: ");
scanf("%s", &username);
printf("Enter your password: ");
scanf("%d", &password); //as you read int you have to use %d
login(username, password);
}
void login(char username[20], int password
{
char un[20];
int pw;
printf("Enter your username: ");
scanf("%s", &un);
if((strcmp(un,username)==0)){
    printf("Enter pass: ");
    scanf("%d", &pw);
    if(pw!=password){
        printf("Password wrong\n");
        login(username, password);
    }
    else{
        menu();
    }
}
else{
    printf("Username wrong\n");
    login(username, password);
}

9

solved so i try to create my simple register and login using c [closed]