Why strcmp(value,curr->value) returns always 0?

I'm using a code like this:

char buffer[LENGTH+1] = {};
while(fscanf(inptr, "%s", buffer) > 0)
  insert( hashtable, buffer );

Then, inside the insert function, I use strcmp function.
Where I'm wrong?

If I use the insert function outside the while fscanf loop, it works as expected.

insert(hashtable, "aword");
  • the best thing you can do is step through your functions using gdb and see what is being stored inside curr->value and value when you are having the issue. – lethaljd Sep 12 '14 at 13:56
  • It seems that, when I'm inside the insert function, curr->value contains the value I've passed (buffer): how can it be possible? – alciregi Sep 12 '14 at 14:40
  • mmm, it is like that every time I read a line in the dictionary, "buffer" value change, and it is like node->value contains a pointer to buffer and not the value. – alciregi Sep 12 '14 at 15:29
  • where are you defining what node->value contains – lethaljd Sep 12 '14 at 15:46
  • I think the problem was in the node struct definition char value[LENGTH+1]; instead of char* value; seems to work better :-) – alciregi Sep 12 '14 at 15:48

Look at the man pages for strcmp function. It returns a value, with 0 meaning that the strings are identical.

  • In fact... but it is always 0, even if they should be different! – alciregi Sep 12 '14 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .