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 {```