1. ## A loop solution

I can't figure out how I can put this in a loop. It is probably really simple but I cant think straight right now.
I tried some things with the % operator but my logic is off Code:
```  map_x = tmp;
map_y = tmp;
map_x = tmp;
map_y = tmp;
map_x = tmp;
map_y = tmp;
map_x = tmp;
map_y = tmp;
map_x = tmp;
map_y = tmp;```
the sizes of map_x, map_y and tmp are not know until runtime. 2. There are multiple ways of doing this.

You could use one counter/variable:
1) Transform the number into a counter.
2) If the counter is odd, place the value in the "y array", in the slot where the counter is divided in half. Otherwise put it in the "x array" using the same method.
3) Repeat until done.

Or you could use multiple variables:
1) Have a loop counter, an "x counter" and a "y counter".
2) Each time through the loop, put the value of the big counter into the x counter. Then increment the big counter, and do the same for the y counter. Now increment the big counter once more.
3) Repeat until done.

There are probably a few other fun ways of doing it, but try both of those and see what one you like better. But definately try both of them as a learning experience.

Quzah. 3. If the size of map_x is equal to the size of map_y, and the size of tmp is equal to 2 * the size of map_x, then you can do something like this:
1) Use a single counter incremented by one on each iteration of the loop, up to the size of map_x
2) The index of map_x and map_y is equal to the counter
3) The index of tmp into map_x is equal to the counter * 2
4) The index of tmp into map_y is equal to the counter * 2 +1

You should be able to assign a value to both map_x and map_y on each iteration through the loop. 4. here is my solution
Code:
```  int i,j=0;
for(i=0;i<sizeof(tmp);i++){ //line 37
if(i%2){
map_x[j] = tmp[i];
}
else{
map_y[j] = tmp[i];
j++;
}
}```
This gives me the right output but i get a warning.
Code:
` Line 37: [Warning] comparison between signed and unsigned integer  expressions`
And the program crashes on exit :s

nm Im going to go back and redesign this function. I'm having more problems with it now. It's time to find a different approach. 5. Are you passing an array (tmp) to this function? If so, you can't use sizeof there. sizeof( arrayname ) on an array passed to a function gives you the size of the pointer, not the array. You can only use that if the array is declared directly in scope.

Quzah. Popular pages Recent additions 