When I run my program it asks for the password indefinitely. I enter the correct password but it simply loops back. There were no errors while I was compiling. To compile, I used:
gcc -ansi -W -Wall -pedantic -o prog myProgram.c
chmod +x prog
I am running ubuntu trusty. Here is the code related to the password:
char string[100] = "";
int main(void)
{
char correctPassword[25] = "myPassword";
char password[25] = "";
system("clear");
printf("Enter your password:\n");
scanf("%s", password);
if (password == correctPassword)
{
system("clear");
printf("Enter a string:\n");
scanf("%s", string);
}
else
{
system("clear");
printf("Sorry, incorrect password\n");
system("pause");
main();
}
updated code:
char string[100] = "";
int main(void)
{
char correctPassword[25] = "myPassword";
char password[25] = "";
int ret;
system("clear");
printf("Enter your password:\n");
scanf("%s", password);
ret = strcmp(password, correctPassword);
if (ret == 0)
{
system("clear");
printf("Enter a string:\n");
scanf("%s", string);
}
else
{
system("clear");
printf("Sorry, incorrect password\n");
system("pause");
main();
}
return 0;
}
edit 2: i think this is beyond solved now, how do i mark it as such?