#include <stdio.h>

void dbiIntToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "%d", *(int*)SrcData);
   return;
}
void dbiCharToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "%c", *(char*)SrcData);
   return;
}
void dbiShortToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "%hd", *(short*)SrcData);
   return;
}
void dbiHexCharToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "0x%hX", *(char*)SrcData);
   return;
}
void dbiHexShortToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "0x%hX", *(short*)SrcData);
   return;
}
void dbiHexIntToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "0x%X", *(int*)SrcData);
   return;
}
void dbiByteToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "%s", (char*)SrcData);
   return;
}
void dbiChrTToStr(void* SrcData, char* DestStr)
{
   sprintf(DestStr, "%s", (char*)SrcData);
   return;
}

int main()
{
  char  pDest[1000];

  
  int den = 12;
  int * pDenI = &den;
  dbiIntToStr(pDenI,pDest);
  printf("%s \n", pDest);

  
  char * pDen = "a1";
  dbiCharToStr(pDen,pDest);
  printf("%s \n", pDest);

  short int denS = 13;
  short int * pDenS = &denS;
  dbiShortToStr(pDenS,pDest);
  printf("%s \n", pDest);
 
  char denHC = 'z';
  char * pDenHC = &denHC;
  dbiHexCharToStr(pDenHC,pDest);
  printf("%s \n",pDest);
  
  
  short int denHS = 253;
  short int * pDenHS = &denHS;
  dbiHexShortToStr(pDenHS,pDest);
  printf("%s \n", pDest);
 
  int denHI = 252;
  int * pDenHI = &denHI;
  dbiHexIntToStr(pDenHI,pDest);
  printf("%s \n",pDest);

  char * pDenB = "10101010";
  dbiByteToStr(pDenB,pDest);
  printf("%s \n",pDest);
  
  char * pDenCT = "garg245arg";
  dbiChrTToStr(pDenCT,pDest);
  printf("%s \n",pDest);
  
  return 0;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Dave Sinkula
0

Why the silliness of having the second parameter be the wrong pointer type, in half the cases, and then casting (redundantly half the time)?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.