user1850610
user1850610

Reputation: 9

Accessing a Character Pointer in a Structure Array

I have an array of pointers to structs that each have a char pointer that is pointing to a string. I want to compare this word to another word.

I compile my code but get this error:request for member word in something not a structure or union. on this line:

strcmp(mytable[i].word, word) == 0)

What am I doing wrong?

Upvotes: 0

Views: 142

Answers (1)

MByD
MByD

Reputation: 137382

If, as you commented, mytable is an array of pointers to structures, then instead of:

mytable[i].word

You should have:

mytable[i]->word

Upvotes: 1

Related Questions