I’m beginner of programmer. I not understande why can’t copy some script from array to another one.
char array1[11];
char array2[2];
array1 = {'255 105 85'};
array2[0] = array1[0];
array2[1] = array1[1];
array2[2] = array1[2];
MessageBox(hwnd,array2,"mes",NULL);
I was get “5” instead of “255”.
I using the code::blocks with GCC complier.The project created with win32 frame based.
Somebody has idea what cause the problem?
The following construct is not allowed in C:
Instead you might consider using the static array initialization like this:
This will fill the array1 with 3 specified values and leave all the other elements set to 0 (i.e. elements starting with index 3 and ending with index 10).
It’s rather surprising, why the compiler didn’t issue a syntax error in your case
updated:
Please also note that you are manipulating with individual characters when you have an expression like this array1[2]. If you want to operate on strings (i.e. have 3 separate strings for the numbers you have specified), you will have to declare something like this:
Thus you will have an array of strings. Each entry of array1 will contain a pointer (address) of the memory where string “255” is located (please note that “255” is an array comprising 4 chars: ‘2’, ‘5’, ‘5’, ‘\0’).