I'm trying to make a simple program which asks for the user to input a name, email and password as a part of signing up, then make him enter the email and password again to log in.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
struct NewUserinfo{
int age;
char name[30], email[50], pass[16];
};
char e1[100], p1[16], e2[100], p2[16], name1[30], userprompt;
printf("Welcome! Would you like to create an account? (y/n) ");
CheckPrompt:
scanf(" %c", &userprompt);
switch(userprompt){
case 'y':
goto newUser;
break;
case 'n':
goto caseN;
break;
default:
printf("Invalid option. Please press \"y\" or \"n\".\n");
goto CheckPrompt;
break;
}
caseN:
printf("Do you already have an account? (y/n) ");
scanf(" %c", &userprompt);
switch(userprompt){
case 'y':
goto alreadyUser;
break;
case 'n':
goto end;
break;
default:
printf("Invalid option. Please press \"y\" or \"n\".\n");
goto caseN;
break;
}
newUser:
printf("Hello there. ");
struct NewUserinfo user1;
printf("What's your name? ");
scanf("%s", user1.name);
strcpy(name1, user1.name);
printf("Your name is %s. ", user1.name);
printf("What's your email? ");
scanf("%s", e1);
strcpy( user1.email, e1);
printf("Your email is %s. What's your password? ", e1);
scanf("%s", p1);
strcpy(user1.pass, p1);
printf("Your password is %s. \n", p1);
printf("Thank you for signing up! Try our log in feature now.\n");
alreadyUser:
printf("Welcome back!\n");
struct NewUserinfo user2;
printf("What's your email? ");
scanf("%s", e2);
strcpy(user2.email, e2);
printf("Your email is %s. What's your password? ", e2);
scanf("%s", p2);
strcpy(user2.pass, p2);
printf("Your password is %s. ", p2);
if(e1 == e2 && p1 == p2){
printf("Welcome, %s.", name1);
}
else if(p1 != p2){
printf("Wrong password.");
goto alreadyUser;
}
else if(e1 != e2){
printf("Invalid email.");
goto alreadyUser;
}
else goto end;
end:
printf("Thank you for your time, %s. ", name1);
getchar();
return 0;
}
The whole thing works just fine until it reaches the login part, where even when I enter the same "email" and "pass" (in my case I just type gg in literally both of them) the output is always "Wrong passord". And if I put the if statement to check the emails above the if statement to check the passwords, it immediately changes to permanent "Invalid Email" where the program will continuously ask me to input what should be the correct "email" and "password". Is there anything that I'm doing wrong here?