I am having trouble with code I am writing to convert a decimal to hexadecimal.
void decToHex (char *decString){
char hexVal[100];
sprintf(hexVal,"%x", *decString);
*decString = hexVal;
return;
}
compilation error: warning: assignment makes a pointer from an integer
without a cast (enabled by default); speaking of the line “*decString
= hexVal;” where I am trying to set my pointer value to the newly discovered hex value.
Does anyone know what I am doing wrong? I have read through some other posts that said this could be an issue with the compiler, however we are required for our class to use the standard c99 compiler built into our putty server. Any ideas on how to do this? I also tried creating an array of ints based on the modulus 16 idea, but I had even more issues with that.
*decStringis a char.hexVal(in this context) is a pointer to char, so you try to store address in a char. hence the error.Even if you will do
decString=hexVal, it will not work, for 2 reasons: it will changedecStringonly in the function, andhexValis a local variable, so it’s not valid outside of the function.Instead of this, copy the string from
hexValtodecString:strcpy(decString, hexVal);.