char to unsigned char

Hi there.

I've a program in C++ which receive an array of chars.
char InputPacketBuffer[64];
Each value of the array has 8bits of ADC conversion that are sended from a microcontroler to the pc, but that chars are unsigned chars(0 to 256 value).
I want to manipulate the array to have a new array with unsigned chars, a new array of [64] with unsigned chars.

1
2
3
4
if(usb_bulk_read(MyLibusbDeviceHandle, 0x81, &InputPacketBuffer[0], 64, 5000) != 64)
				 {
					 return;
				 }

I ve to do it after this instruction because the usb program just allow an array declared like char InputPacketBuffer[64];

Can anyone help me?
Thanks in advance.
Try this:

1
2
3
4
5
6
7

unsigned char ucBuffer[ 64 ];

/*   call usb_bulk_read():    */

memcpy( ucBuffer, InputPacketBuffer, sizeof( ucBuffer ) );
No need to duplicate the buffer I'd say:

1
2
3
unsigned char *ucBuffer = InputPacketBuffer;
//Or if the above turns out to be invalid syntax, use:
unsigned char *ucBuffer = &InputPacketBuffer[0];
Neither of them worked...

In the first (kooth) it builded, but it didn't work. I've a chart were I display the values, and I've 32 values received throw usb, forming a slope. When they are displayed the values above 127 are wrong, instead of being 28; 29; 30; 31 they are completely different.

In the second (webJose), the first case I got build error:
error C2440: 'initializing' : cannot convert from 'char [64]' to 'unsigned char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
and in the second case, buid error again:
error C2440: 'initializing' : cannot convert from 'char *' to 'unsigned char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Any idea?

Thanks
Yes. The fix is SUPER SIMPLE: unsigned char *ucBuffer = (unsigned char*)&InputPacketBuffer[0];
memcpy( ucBuffer, InputPacketBuffer, sizeof( ucBuffer ) );
worked =)
I wasn't diplaying the right array in my char, but the values saved on the file were ok.

Thank you all.
Topic archived. No new replies allowed.