3-dimensional array

hey everyone,

i have a problem about a three dimensional-array. how do you assign a null-string to the array??

hier is the declaration of the array and the strcpy-function:

1
2
3
4
5
6
7
8
9
10
11
12
13
char namen[7][100][200];
...
//voor elke layer in de array
     for(laycount=1;laycount<=6;laycount++)
     {
          //voor elke rij in de array
          for (rowcount=1;rowcount<=100;rowcount++)
          {
              //reset elke string naar een null-string
              strcpy(namen[laycount][rowcount] ,"");
          }
     }
...



can someone help me?
namen[laycount][rowcount][0]=0;

Your for indices are wrong. You're not iterating over element 0.

Be careful with multidimensional arrays. They're just 1D arrays which the compiler performs a little offset arithmetic on. For example, your code is equivalent to this:
1
2
3
4
5
6
7
8
9
10
//char namen[7][100][200];
char namen[7*100*200];
//index fixed:
for(laycount=0;laycount<7;laycount++){
	//also here:
	for (rowcount=0;rowcount<100;rowcount++)
		//namen[laycount][rowcount][0]=0;
		namen[laycount*100*200+rowcount*200]=0;
}
Last edited on
Ok, but is there a way to keep the three dimensional array?
Last edited on
I don't understand what you're asking. Did I tell to get rid of it?
Topic archived. No new replies allowed.