1

I have a pointer which point to a memory of 20 bytes, and then copy something to the memory

u_char* pkt=malloc(20);
memcpy(pkt, somecontent, 20);

I want to examine the 20 bytes starting from pkt so I want to print all the bytes with a format like 0xa6 how to do this in language C

thanks!

user1944267
  • 1,557
  • 5
  • 20
  • 27

2 Answers2

2

Try printf :

int i=0;
for (; i<20; i++)
  printf("0x%.2x ", pkt[i]);
printf("\n");
WhozCraig
  • 65,258
  • 11
  • 75
  • 141
masoud
  • 55,379
  • 16
  • 141
  • 208
  • That is exactly what this man needed, but I'd also suggest him reading printf man pages, for example here: http://linux.die.net/man/3/printf – Sergey Savenko Mar 20 '13 at 18:33
0

The following code is sufficient,

int i=0;
u_char  * ptr=pkt;
for (; i<20; i++)
  printf("%x ", ptr++);
printf("\n");
Deepu
  • 7,592
  • 4
  • 25
  • 47