Reputation: 118
I have a function that currently returns unsigned char
. However, I want to cast that unsigned char
to a char*
but I keep getting cast to/from pointer from/to integer of different size warning.
Let foo
be the function that return an unsigned char
I tried something like this:
char* convert = (char*)foo();
The reason for converting to char*
is because I need to use the strcasecmp
function to perform a string compare.
Upvotes: 1
Views: 995
Reputation: 5550
You can't cast a non-pointer function return value into a pointer at all. Think about it, where would this pointer point to?
You can, however, save the result to a variable and have a pointer to it. For example,
char tmp = (char) foo();
char * ptr = &tmp;
Edit:
As another answer said, if you want to use strcasecmp
you would need a char
array where the last byte is the null terminator.
Upvotes: 2
Reputation: 52530
To achieve what you want, use the following code:
char array [2];
array [0] = (char) foo ();
array [1] = '\0';
...
... strcasecmp (array, ...);
This builds an array containing a string of a single character which you can then use.
Upvotes: 2