1. ## run-time var initialization

In plain C, when initializing a matrix you can do it:
int m[2][2] = { {2,3} , {3,4} };
but I am trying to do it at run time:

Code:
```int F[5][8];

int main()
{
int x= 1;
F[x] = {-6, -3, 0, 4, 8, 6, 2, -4 };
int x= 2;
F[x] = {-7, -3, 0, 5, 8, 6, 2, -8 };
.....
return 0;
}```
And I get compiling errors. It looks like this way is not allowed.

Is there any way to inialize a matriz in bulk, so that there is no need to initialize values one by one.

thanks

2. int m[2][2] = { {2,3} , {3,4} };

3. Originally Posted by Bayint Naung
int m[2][2] = { {2,3} , {3,4} };
That is not what I want. suppose I want to initialize it depending on a var:

Code:
```int F[5][8];

int main()
{
if (z == 18) {
F[1] = {-6, -3, 0, 4, 8, 6, 2, -4 };
} else {
F[1] = {-7, -3, 0, 5, 8, 6, 2, -8 };
}
.....
return 0;
}```
I can not do this also. any idea or I must do it value by value?

4. Code:
```
if (z == 18) {
int temp[] =  {-6, -3, 0, 4, 8, 6, 2, -4 };
/* of course you can use
#define  INIT_ARRAY  { -6, -3,0,blah}  int temp[] = INIT_ARRAY;
*/
// copy
memcpy(f[1],temp,sizeof(temp));
} else {
int temp[] = {-7, -3, 0, 5, 8, 6, 2, -8 };
// similar
}```
Or use variadic macro. Example (Not suppose to be perfect
Code:
```#define INIT_ARRAY(array,type,...)    \
do {                                                                    \
memcpy(array,  ( type [ sizeof(array)/sizeof(array[0]) ]) { __VA_ARGS__ }, sizeof(array) );   \
} while(0)
INIT_ARRAY(f[1],int, 3,4,5 );     // eg usage
} while(0)```

5. macro? memcpy? stay away

just make a new array and copy over the contents

Code:
```        if (z == 18) {
int temp[] = {-6, -3, 0, 4, 8, 6, 2, -4 };
for(...) {
F[1][i] = temp[i]
}
} else {```
when writing a program, the first thing you should do is get something that works and is correct. then go back and do whatever you feel is required. i think you knew exactly how to get around this problem by using a temp array and i dont think you should have spent any more than a few seconds trying to think of better method. the temp array solution was simple, obvious and clear.

its like when you are writing an essay at home. the first thing you should do is write it all out. then you should go and choose fonts, choose header styles, colors, pictures, etc. but only after youve finished

and use spaces, not tabs. if you must use tabs, then dont mix and match with spaces.