problem with array position copying...

Non-platform specific questions.

problem with array position copying...

Postby Sgt. Sparky » Wed Apr 18, 2007 7:37 pm

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? :(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Wed Apr 18, 2007 10:39 pm

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.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Wed Apr 18, 2007 11:17 pm

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. :(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Thu Apr 19, 2007 12:10 am

Can you show the variable declaration?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Thu Apr 19, 2007 12:23 am

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);
}

:(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Thu Apr 19, 2007 1:02 am

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Thu Apr 19, 2007 2:15 am

all I am trying to do is access one string in a spacific spot,
the [i] position. :(
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Thu Apr 19, 2007 2:20 am

Declare the smpl2 variable as above, and access like this:

Code: Select all
strcpy(smpl2[i] , t);
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Sgt. Sparky » Thu Apr 19, 2007 2:23 am

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?
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby makslane » Thu Apr 19, 2007 2:41 am

Yes, you need to use this king of declaration for string arrays.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest