The strcmp() function is not working. The username I am reading from console doesn't match the one i Have in the file. So, the output is wrong id.
What is the solution?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE *pass;
char str[100],str2[100];
char id[100],pw[100];
pass=fopen("password.txt","r");
printf("ENTER USER NAME AND PASSWORD:\n");
printf("USERNAME: ");
gets(id);
printf("\nPASSWORD: ");
gets(pw);
while(fgets(str,100,pass)!=NULL);
{
fgets(str2,100,pass);
if(strcmp(id,str)==0)
{
if(strcmp(pw,str2)==0)
{
printf("ACCEPTED\n");
}
else
{
printf("wrong password");
}
}
else
{
printf("wrong id");
}
}
fclose(pass);
}