return makes integer from pointer without a cast [-Wint-conversion] return candidate

Your local variable candidate is an array of char. When you say

return candidate;

you return a pointer to char. (This is due to the very close relationship between arrays and pointers in C, which you will have to learn about if you don’t know yet.) But you’ve stated that your function getkey returns a char, not a pointer-to-char.

You need to make the function’s return value match its type. You might want change the return statement so it returns a single char. If you want to have the function return a whole string, you could change its declaration to char *getkey(), but in that case you’ll also have to take care of the allocation of the candidate array.

Here’s what the warning means. You tried to return a pointer. The function is supposed to return a character, which is represented as a small integer. The compile is willing to try to convert the pointer to an integer, in case that’s what you really want to do, but since that’s not usually a good idea, it warns you. Indeed, in this case the warning tells you that you probably made a mistake.

Leave a Comment