This is a simple C authentication program that went wrong. It's reading the strings from the console as a username and password as input correct, but the username input has becomes blank space string. What might be the mistake?
Code:
#include <stdio.h>
int main()
{
char username[4];
char password[8];
printf("Enter username: ");
scanf("%s", username);
printf("Enter password: ");
scanf("%s", password);
if (username == "ojas" && password == "ojas1234")
{
printf("Access granted!");
}
else
{
printf("%s and %s\n", username, password);
printf("Access denied");
}
return 0;
}
Output
Enter username: ojas
Enter password: ojas1234
and ojas1234
Access denied