hex array to ascii string

I have an array that has encoded the serial number of a device. The values in the array are the numbers for the respective ascii characters. I just need to print the serial number. BTW, for historical reasons, I'm using VC++ 6.0.

1
2
3
4
5
6
7
8
9
10
11
12
 static void _Read_Page2 (Aardvark handle, u08 device)
{
    char SN[16]; 
    int count, i;
    u08 *data_in = (u08 *)malloc(128);
/*
...
/*
    printf(" Serial Number = ") ;
    for (i=0; i<16 ; i++) {SN[i] = data_in[i+0xE4] ; printf("%c",SN[i]) ;}  
    printf("/n") ;
} */


my data_in looks like this (in hex):
00e0: 00 00 00 00 47 31 33 31 39 35 48 30 39 32 32 20 20 20 20 20

Characters printed out are nonsense. What am I missing?
You allocated for data_in 128 characters that in hex is equal to 0x80. But in the loop you are trying to access characters with indexes greater than 0xE4. The allocated array has no elements with such indexes. The maximum index that can be used with the array is 0x80 - 1

SN[i] = data_in[i+0xE4] ;
Last edited on
Duhhhh... Thanks. Now works like a charm. I was reading two different pages of 128 bytes each, and was looking at memory locations for page 2.
Topic archived. No new replies allowed.