#6781 - einhaender - Mon Jun 02, 2003 6:56 pm
Hi, iam new to C/C++ so maybe theres someone to help me on this one.
I have multiple header files holding u16 arrays, like:
const u16 tile_1_1Data[] = { ... }
const u16 tile_2_1Data[] = { ... }
now in my main file I need to iterate through all these array but I dont wanna write the for loop over and over again. so somehow i need to
assign to a new Array the actual Array that I wanna iterate. I thought of something like:
u16 new_array[1]; //
for(int i = 0; ...... ) {
switch(i) {
case 1: new_array[0] = tile_1_1Data;
break;
etc. etc.
}
for(int n = 0; ......) {
u16 test = new_array[0][n]; // this should be tile_1_1Data if i==0
}
}
The idea is to put the array to iterate into new_array[0] and get a multidimensional array. It doesnt work however?
Iam not too familar with pointers but iam sure theres a much better
solution.
Also is there a way in a for loop to limit iterations to the array's size?
This question may sound stupid but all sample code snippets have the
number of iterations hardcoded, i.e for(int i=0; i < 128 ....
I have multiple header files holding u16 arrays, like:
const u16 tile_1_1Data[] = { ... }
const u16 tile_2_1Data[] = { ... }
now in my main file I need to iterate through all these array but I dont wanna write the for loop over and over again. so somehow i need to
assign to a new Array the actual Array that I wanna iterate. I thought of something like:
u16 new_array[1]; //
for(int i = 0; ...... ) {
switch(i) {
case 1: new_array[0] = tile_1_1Data;
break;
etc. etc.
}
for(int n = 0; ......) {
u16 test = new_array[0][n]; // this should be tile_1_1Data if i==0
}
}
The idea is to put the array to iterate into new_array[0] and get a multidimensional array. It doesnt work however?
Iam not too familar with pointers but iam sure theres a much better
solution.
Also is there a way in a for loop to limit iterations to the array's size?
This question may sound stupid but all sample code snippets have the
number of iterations hardcoded, i.e for(int i=0; i < 128 ....