#include <stdio.h>
#include<string.h>
void printByteArrayElements(char* inputArray, int size)
{
long i;
char StrBuff[200] = {0};
if (size * 5 > 200)
{
printf("print input data buffer in hex form impossible because of too many data (%d)\n", size);
}
for(i=0; i < size; i++)
{
char tmp[5];
strncat(StrBuff, "0x", 2);
snprintf(tmp, sizeof(tmp), "%02X", inputArray[i]);
printf("tmp = '%s'\n", tmp);
strncat(StrBuff, tmp, sizeof(tmp));
if(i < size - 1)
{
strncat(StrBuff, " ", 1);
}
}
printf("Data Size = %d, Data Element = '%s'\n", size, StrBuff);
}
int main()
{
char dataElement = 0;
char inputArray[20] = {0, 0, 0};
printf("dataElement = 0x%02X\n", dataElement);
printByteArrayElements(inputArray, 20);
return 0;
}
dataElement = 0x00
tmp = ’00’
Data Size = 20, Data Element = ‘0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00’