Hello,
I am trying to pass in a long int value and return an array of pointers which is processed in a function that converts long to hex. The array doesn't seem to return from the function. I get an error of the type " type mismatch in redeclaration of long2hex". Please do give me pointers on how to go about the issue.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void main()
{
long a;
char *b[5];
a=229605;
*b=long2hex(a);
printf("\n%s\n",b[0]);
printf("%s",b[1]);
}
char *long2hex(long c)
{
int i,rem;
char hex_val[8],hex_valr[8],*ptr,*ptr1,temp,temp0,temp1,temp4,temp5;
char *putval[5];
i=0;
while(c>0)
{
rem=c%16;
c=c/16;
if(rem>9)
{
hex_val[i]=(char)rem+55;
}
else
{
hex_val[i]=(char)rem+48;
}
i++;
}
hex_val[i]='\0';
// printf("\n %ld",fchksz);
printf("\n %s",hex_val);
ptr=hex_val;
ptr1=hex_valr;
ptr+=strlen(hex_val)-1;
for (i=0;i<strlen(hex_val);i++)
{
*ptr1=*ptr;
ptr1++;
ptr--;
}
hex_valr[5]='\0';
printf("\n %s",hex_valr);
for(i=strlen(hex_valr);i>0;i--)
{
temp=hex_valr[i];
hex_valr[i]=hex_valr[i-1];
hex_valr[i+1]=temp;
}
hex_valr[0]='0';
printf("\n");
for (i=0;i<strlen(hex_valr);i++)
{
printf(" %c",hex_valr[i]);
}
printf("\n");
temp0=hex_valr[0];
temp1=hex_valr[1];
temp4=hex_valr[4];
temp5=hex_valr[5];
hex_valr[0]=temp4;
hex_valr[1]=temp5;
hex_valr[4]=temp0;
hex_valr[5]=temp1;
printf("\n");
for (i=0;i<strlen(hex_valr);i++)
{
printf(" %c",hex_valr[i]);
}
sprintf(putval[0],"%c%c",hex_valr[0],hex_valr[1]);
sprintf(putval[1],"%c%c",hex_valr[2],hex_valr[3]);
sprintf(putval[2],"%c%c",hex_valr[4],hex_valr[5]);
sprintf(putval[3],"00");
printf("\n");
printf("%s ",putval[0]);
printf("%s ",putval[1]);
printf("%s ",putval[2]);
return (char*)putval;
}