What's the syntax? For example, I would like to achieve the following:
...Only this way:Code:int a[3] = {1, 2, 3};
Code:int a[3]; ... //syntax goes here for achieving the same darn thing //and I do not want to do a[0] = 1, a[1] = 2, etc
What's the syntax? For example, I would like to achieve the following:
...Only this way:Code:int a[3] = {1, 2, 3};
Code:int a[3]; ... //syntax goes here for achieving the same darn thing //and I do not want to do a[0] = 1, a[1] = 2, etc
Last edited by fd9; 12-02-2005 at 10:07 PM.
When you do this the compiler places the values in the executable and creates an array who's address is the first value. At run time the only way to assign values is for those values to be moved into the location of the variables. Therefor if it were possible to do something like that at run time (after an array was allready declared) it would result in lots of assignmentsCode:int a[3] = {1, 2, 3};
The closest thing you could do is to set up an array as above and then use memcpy to copy the contents to another array.Code:a[0]=1; [1]=2; ...
Use a loop and assign to each member of the array.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Woop?
By definition, you can't initialize an array after defining it.Simply initializing an array AFTER defining it
The thing is I need to initilize it in a "visual way", which I can only do using the syntax in my first post. My only other choice is to look into those other functions. - ThanksOriginally Posted by Dave_Sinkula
You could always store your data in a file and read it in.
Well, here's an obfuscation:Originally Posted by fd9
Any more "visual"?Code:static const struct block { int z[3]; } init = {{1,2,3}}; int a[3]; *(struct block*)a = init;
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*