I want to compare string user input and a string from textfile.
I am comparing the value of the uname and the current value of the storage. It goes inside the while loop but when they match, it doesn't proceed to the if block which supposed to do the test if the storage and uname have the same value.
void compare()
{
char uname[20];
FILE *list = fopen("list.txt","a");
if(list == NULL)
{
printf("Textfile doesn't have any content\n");
}
printf("Enter username: ");
scanf("%s",&uname);
fprintf(list,"%s\n",uname);
fclose(list);
list = fopen("listahan.txt","r");
char storage[50]; //storage of the string that I will get from the textfile
if(list != NULL) //check if list have content
{
while((fgets(storage,sizeof(storage),list) != NULL)) //if list have content, get it line by line and compare it to the uname.
{
printf("storage:%s\n",storage); // for debug, checks the current value of storage
printf("uname:%s\n",uname); //for debug, checks the value of uname
if(storage == uname) //this if block is being ignored, even when the storage and uname match, the block does not execute.
{
printf("Login Success!\n");
}
}
}