I've posted on this one before and got advice that has got me to almost finish this pset (thanks, blauelf!), but now I'm totally stuck. Everything seems to work except for I can't get the word from the text to lower case to check for the hash value and compare with the dict word. I know it has to be converted before the hash function or the ASCII values are different and it doesn't go to the right 'bucket' if there are any uppercase letters. But I'm still struggling with the function I've written to get the word to lowercase - I get the error "incompatible integer to pointer conversion assigning to 'const char *' from 'char'". I just can't work out which bit is causing the problem - as far as I can see all the vars are const char *'s so where is the 'char'? The code is here: http://pastebin.com/Yd3h3Fqe Thankyou! Cally


This word = strcicmp(word); doesn't compile because word is a const char* and strcicmp returns a const char.1 You can't do this word = strcicmp(word); anyway because word is a const and as such cannot be changed.

A serious problem with the strcicmp function: It returns after it processes the first letter in the string.

The dilemma is: word is a const therefore cannot be changed. But it needs to be "changed" into lower case for the hash function. What to do? One option would be to declare and allocate a new string, copy word into it (letter-by-letter transforming to lower case as you go), and send the lower-case word to hash. [You can send a char * to a function that declares it's argument as const char *, because a const function argument will accept a type that is "less strict".] You could do it in a function or in-line in the check routine. Don't forget to properly allocate and null terminate any string you create. You could use the lower-case word for comparing, too (or strcasecmp with word?).

1Don't you also get a compile error that 'const' type qualifier on return type has no effect? If not, maybe you are not on the current IDE version (98 as of this writing) and update50 is in order.

  • Thank you so much for replying!! Sorry for the delay in getting back - I was out on my bike having got too brain addled to continue! Now I get why strcicmp didn't compile - but I can't seem to get the copying word into a new string as you suggest - I tried this: //copy word to string for (int i = 0; i<(strlen(word)+1); i++) { char *word_t[i] = word[i]; if (word_t[i] == (strlen(word)+1)) { word_t[i] = '\0'; } } and got 5 errors inc the same incompatibility error (that's obv not right!...cd u help?! – CallyB Feb 17 '17 at 15:00
  • Fresh air is sometimes just the thing. You need to declare and allocate word_t once before you start the loop. So this ` char *word_t[i] = word[i];` would become this word_t[i] - tolower(word[i]) (don't forget the tolower, else what's the point???). Hint, if you use char* word_t = calloc(strlen(word) + 1,1); instead of malloc, that will initialize all the bytes to 0, and you do not have to worry about terminating it. You do have to remember to free it. – DinoCoderSaurus Feb 17 '17 at 15:08
  • Thank you again! I'm in the school yard now but will try this as soon as I get back! I was obv initializing the new word wrong - I tried several ways but just got error msg's each time so thank you for the clarity - & ill deffo add the tolower this time - I was being lazy in my eagerness to see it working! – CallyB Feb 17 '17 at 15:29
  • Oh, & I seem to be on ID 99?!!!! – CallyB Feb 17 '17 at 15:30
  • Yayyy! it's passing check50! Thank you DinoCoderSaurus!! I've finished it with a 5 yr old on my knee and had to look up calloc to understand the syntax but it's finally working....phewwwwww! Pset6 here I come! :-) – CallyB Feb 17 '17 at 19:30

You must log in to answer this question.

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