What's wrong with this code: arrays?

gormster's Avatar, Join Date: Dec 2007
Newbie Member
Code:
- (void) sendMessage:(int) type data:(char[]) data length:(int)length
{
	++length;
	char message[length];
	message[0] = type;
	printf("%X",message[0]);
}
I know this is in Obj-C but the important part is pure C. The weird bit at the top is just Obj-C's way of making an instance method. Basically, length and type are both integers.

So, I pass 0x90 to 'type', and the printf gives me FFFFFF90. If I printf message[1] or [2], I get 7 and FFFFFF84, respectively. They should, of course, be empty.

So, what the hell is going on? I feel I have made some kind of rookie mistake.
0
gormster's Avatar, Join Date: Dec 2007
Newbie Member
PS: I should mention that if I replace the message[0] = type with message[0] = 0x90, it works fine.