im new into programming and one of my assignments is to build a login system in c, where the username and the password are stored inside a .txt file, the .txt file looks like this
danielR
77bd
(top is the username and below is the password)
the problem is when I compare the two strings from user input and from the .txt file of both username and password using strcmp(), it doesnt return to 0 even tho both strings are equal
#include <stdio.h)
#include <conio.h>
#include <string.h>
#include <stdlib.h>
struct login
{
char name[25];
char pass[25];
};
void login()
{
struct login acc1,acc2;
printf("input your username : ");
scanf ("%s",acc1.name);
printf("input your password : ");
scanf ("%s",acc1.pass);
FILE* fp = fopen("account.txt","r");
fgets(acc2.name,25,fp);
fgets(acc2.pass,25,fp);
if (strcmp(acc1.name,acc2.name)==0 && strcmp(acc1.pass,acc2.pass)==0)
{
printf("login successful\n");
}
else
{
printf("wrong password or username");
}
I've even tried using printf to match the usernames and passwords from userinput and from .txt files and they all are equal. I wonder why strcmp() doesnt return to 0. any help?