Qeustion: DIM[][]

Non-platform specific questions.

Qeustion: DIM[][]

Postby equinox » Tue Mar 31, 2009 4:43 pm

HI at ALL,

global: char VetMAGIA[0][10];// Nome MAGIA

for(i = 0; i < 10; i += 1){
strcpy(VetMAGIA[0][i], "NoMagic");<----error: why?
}

Tnk1000 for help.


print -> VetMAGIA[0][0]---> "magic 1"
....
print -> VetMAGIA[0][n]---> "magic 2"......

i wish a NOT 2 dimensional array of characters, BUT an array of "strings".

with GE but I do not know how. Somebody knows?
Attachments
Image1.png
Last edited by equinox on Tue Mar 31, 2009 6:11 pm, edited 7 times in total.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: Qeustion: DIM[][]

Postby asmodeus » Tue Mar 31, 2009 4:57 pm

Don't forget to close the loop (}), if it isn't in your code.
I don't really know what the error is, but I know something that strings are just array variables.
If I know it correctly, it should be something like that:
"Hello" would be in the variable myString like myString[0]='H', myString[1]='e', myString[2]='l' and so on.
I'm not sure if that has to do with your error.
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: Qeustion: DIM[][]

Postby skydereign » Tue Mar 31, 2009 11:10 pm

char VetMAGIA[0][10];// Nome MAGIA
Does it let you get away with a zero in the sub? Or are you explaining the subs, not showing the declarations?

for(i = 0; i < 10; i += 1){
strcpy(VetMAGIA[0][i], "NoMagic");<----error: why?
}
I think there is an error here as you are giving it a char, not a char*. A string is a char *, or char[]. I am not sure what you are trying to do, but VetMAGIA is supposed to be a string, then the for loop won't work. You would need to create a temp string and assign values, then check that. Right now you are using a char array and checking individual characters. You want an array of strings so you should make an array of char*s.
Code: Select all
char* VetMAGIA[10];
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Qeustion: DIM[][]

Postby equinox » Wed Apr 01, 2009 12:22 pm

I try to explain better:

CODE GLOBAL:
int E = 2;<<--Eroe1,Eroe2....
char VetMAGIC[E][10];// Nome MAGIA
-------------------------------------------------
VetMAGIA[0][0]---> "Name magic 0"....for Eroe1
VetMAGIA[0][1]---> "Name magic 1"
----------------------------------------------
VetMAGIA[1][0]---> "Name magic 0"....for Eroe2
VetMAGIA[1][1]---> "Name magic 1"
----------------------------------------------
for(i = 0; i < 10; i += 1){// initializze for start the level for Eroe1
strcpy(VetMAGIA[0][i], "NoMagic");<----error: why?
}
...i like to print:
print -> VetMAGIA[0][0]---> "magic 1"
....
print -> VetMAGIA[0][n]---> "magic 2"......
=========================

char* VetMAGIC[E][10];<---not work.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: Qeustion: DIM[][]

Postby makslane » Wed Apr 01, 2009 1:34 pm

You need declare:

char VetMAGIC[max number of heroes][max number of strings][max lenght of each string];
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Qeustion: DIM[][]

Postby equinox » Wed Apr 01, 2009 4:12 pm

Tnk MAK,

I did not believe that one could create 3d array.

I meanwhile, I tried this and seems to work.

second you can work?

not char* VetMAGIA[3][16];// Nome MAGIA
...but
char *VetMAGIA[3][16];// Nome MAGIA


,,, just that now I can not compare
Attachments
Image1.jpg
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: Qeustion: DIM[][]

Postby makslane » Wed Apr 01, 2009 9:43 pm

Try aput a cast:
strcmp((char *)VetMAGIA[i], ...
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Re: Qeustion: DIM[][]

Postby equinox » Thu Apr 02, 2009 4:34 pm

K, i try in this mode.

TNk1000 fro help.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron