1. ## about decimal to hex progam

hi everyone,

I am trying to implement a program that converts a decimal into
Hex, I am having some problem it doesn't do the right computation, can anyone see any abnormality of my implementaion.

Here is the code:

Code:
```code
/* this function decimal number and transforms into hex */
char HexConvert(int val)
{
char  *iter = val+10;

while(iter>=val+2){
/*compute hex digit*/
if(val)
{
*iter = val%16;
val/=16;

if(*iter<10) /*output integer*/
*iter+='0';
return iter;
else         /*output character*/
*iter+=55; /* ASCII Value for A (=10) is 65 (=55+10) */
return iter;
}
else /*fill remaining hex array with zeros*/
*iter = '0';
return iter;
iter--;

}```

2. You have some problems with iter, because it points to a relatively random memory location with the address of val's content + 10.
Also, there's actually no need for an if-test, just try something like;

Code:
```#include <stdio.h>

int main()
{
char buf[11],
buf2[11],
i = 0,
j;
int val = 255;
while( val )
buf[i] = "0123456789ABCDEF"[ val % 16 ], val /= 16, ++i;
buf[i] = 0;
for( i -= 1, j = 0; i > -1; i--, j++ )
buf2[j] = buf[i];
buf2[j] = 0;
puts( buf2 );
return 0;
}```

3. Code:
```int a=10;/*decimal*/