Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Assigning with a Pointer to Array of Chars

I have the following test code and it is not working:

char a[30];
char (*b)[30];
b = &a;
char (**c)[30];
c = &b;
(*c)[0] = a[1]; // error C2440: '=' : cannot convert from 'char' to 'char [30]'

Why is this happenning? Why is this not working?

Tks,

fsn. :)
[341 byte] By [fsn] at [2007-11-11 7:19:32]
# 1 Re: Assigning with a Pointer to Array of Chars
c is a pointer to a pointer of type "character array of 30 elements". a[1] is a pointer to a character. There is a type mismatch between a character array of 30 elements and a character.
nspils at 2007-11-11 21:02:28 >
# 2 Re: Assigning with a Pointer to Array of Chars
It should be:

(**c)[0] = a[1];

(*c)[0] is a pointer, so you need to dereference it by adding an extra *.
Danny at 2007-11-11 21:03:28 >
# 3 Re: Assigning with a Pointer to Array of Chars
Tks!

fsn :)
fsn at 2007-11-11 21:04:26 >