-1

I'm building a linked list that builds/tracks a movie database. In my search function I have an if statement that checks if the pointer to the title of the movie is equal to the inputted value in the search function. However, the if statement does not run even though the values are equal to each other. I didn't want to include all of my code so I included both input fields for the if statement and the loop the if statement sits in. I have validated that the values of movieTitle and ptr->title are lexically the same.

ptr->title input

printf("Name of the Movie: ");
scanf(" %[^\n]%*c", m.title);
strcpy(ptr->title, m.title);

movieTitle input

printf("Name of the Movie: ");
scanf(" %[^\n]%*c", movieTitle);

If Statement

while (ptr != NULL)
{       
    if (movieTitle == ptr->title)
    {
        printf("Year: %d\n", ptr->year);
        printf("Rating: %hhu\n", ptr->rating);
        found = true;
        break;
    }
    else
    {
        tmp = ptr;
        ptr = ptr->next;
    }
}
asdf
  • 2,927
  • 2
  • 21
  • 42

1 Answers1

3

You can't use == to compare two strings in C

using strcmp

Something like this

if (strcmp( string1, string2) == 0) 
gmlacrosse
  • 362
  • 2
  • 8