0

I'm relatively new to to programming and even after doing a thorough research I am not able to solve this problem.

I want to check whether through an object [defined as of variable type union] I can compare with a new object entered by the user for the entered object is in this particular set or not, but always two errors are popping up: "invalid type argument of unary '*' (have 'Object')"

bool is_element_of(Object items, SET*S)
{
  LIST*scan = *S;
  int p = 0;
  while (S != NULL)
  {
    if (*scan->item == items)
      p = 1;
    scan = scan->next;
  }
  if (p == 1)
    return true;
  else
    return false;
}

here is the struct definition along with the union of the object:

typedef struct object
{
  union
  {
    char c;
    char t[OSIZE];
    unsigned long int h[OSIZE];
    unsigned int i;
    float f;
    long double j[OSIZE];
    int type;
  } TYPE;
} Object;

typedef struct list1
{
  Object item;
  struct list1*next;
} LIST;

typedef LIST*SET;
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • 4
    What are you trying to do with `*scan->item`? Beware that it's parsed as `*(scan->item)`, probably you meant `(*scan)->item` instead? Or just `scan->item`? Or...? –  Dec 24 '13 at 14:13
  • This `LIST*scan` may also be your problem. Try adding a space there. – StoryTeller - Unslander Monica Dec 24 '13 at 14:18
  • 1
    Note that `while (S != NULL)` should be `while (scan != NULL)`, but you should either test `p != 0` or use `break` after setting `p = 1;` since there's no point in scanning the rest of the set once you know the answer. Or even do `return true;` if you find the match, and a simple `return false;` at the end if you get there, dropping the variable `p` altogether. (Don't believe the single-entry/single-exit school entirely — this is a case where early return is completely understandable and far simpler than the alternatives.) – Jonathan Leffler Dec 24 '13 at 14:25
  • Basically what I wanted to do was merely in terms "scan" the contents of the the item in scan which points to the original to set to check whether there is a match for both items,that was the aim at least – user3132653 Dec 24 '13 at 15:27
  • also I tried (*scan) still didn't work . Any ideas? – user3132653 Dec 24 '13 at 15:37
  • if (scan->item == items) returns invalid operands to binary. – user3132653 Dec 24 '13 at 15:39

1 Answers1

2
if (*scan->item == items)

scan->item is an Object, not a pointer. So you can't dereference it.

sepp2k
  • 363,768
  • 54
  • 674
  • 675