Page 1 of 1

problem with array position copying...

PostPosted: Wed Apr 18, 2007 7:37 pm
by Sgt. Sparky
this is the part of the code where I get the error,
I have all the ints and chars set up.
Code: Select all
for(i = 0, l = strlen(smpl)-1; i < l; i++, l--) {
      strcpy(smpl2[i], "*");
      }

the problem is with the strcpy(smpl2[i], "*");
when I remove the [i] it will accept it,
but it will not do the function right because it just copying 1 char,
when I do the array it is supposed to use the array position which is i.
what do I need to do? :(

PostPosted: Wed Apr 18, 2007 10:39 pm
by makslane
If smpl2 is a string, you have access to the letters by using the array notation. So, smpl2[0] is the first char.

If you want a array of strings. You can use the array option in the Variables panel.

PostPosted: Wed Apr 18, 2007 11:17 pm
by Sgt. Sparky
I did make the array in global code,
the problem is GE will not accept it.
and when I put and & before it it accepted it but the code did not work. :(

PostPosted: Thu Apr 19, 2007 12:10 am
by makslane
Can you show the variable declaration?

PostPosted: Thu Apr 19, 2007 12:23 am
by Sgt. Sparky
I will just post all I have of the code so far,

Code: Select all
char smple[255];
char smpl2[255];
void star_out(char s[255], char t[1])
{
 int l, c, i, started;
 if(started == 0)
 {
     c = 1;
     strcpy(smple, s);
     started = 1;
 }
 for(i = 0, l = strlen(smpl)-1; i < l; i++, l--) {
      strcpy(&smpl2[i] , t);
      }
 if(i >= l)strcpy(s, smpl2);
}

:(

PostPosted: Thu Apr 19, 2007 1:02 am
by makslane
The right declaration for a array of strings is:

Code: Select all
char smpl2[32][255]; //Up to 32 strings with 254 as maximum lenght

PostPosted: Thu Apr 19, 2007 2:15 am
by Sgt. Sparky
all I am trying to do is access one string in a spacific spot,
the [i] position. :(

PostPosted: Thu Apr 19, 2007 2:20 am
by makslane
Declare the smpl2 variable as above, and access like this:

Code: Select all
strcpy(smpl2[i] , t);

PostPosted: Thu Apr 19, 2007 2:23 am
by Sgt. Sparky
that is how I got the error in the first place,
it will not let me use the code.

or do I use the smpl2[32][255] and it will work?

PostPosted: Thu Apr 19, 2007 2:41 am
by makslane
Yes, you need to use this king of declaration for string arrays.