Page 1 of 1
Qeustion: DIM[][]
Posted:
Tue Mar 31, 2009 4:43 pm
by equinox
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?
Re: Qeustion: DIM[][]
Posted:
Tue Mar 31, 2009 4:57 pm
by asmodeus
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.
Re: Qeustion: DIM[][]
Posted:
Tue Mar 31, 2009 11:10 pm
by skydereign
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];
Re: Qeustion: DIM[][]
Posted:
Wed Apr 01, 2009 12:22 pm
by equinox
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.
Re: Qeustion: DIM[][]
Posted:
Wed Apr 01, 2009 1:34 pm
by makslane
You need declare:
char VetMAGIC[max number of heroes][max number of strings][max lenght of each string];
Re: Qeustion: DIM[][]
Posted:
Wed Apr 01, 2009 4:12 pm
by equinox
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
Re: Qeustion: DIM[][]
Posted:
Wed Apr 01, 2009 9:43 pm
by makslane
Try aput a cast:
strcmp((char *)VetMAGIA[i], ...
Re: Qeustion: DIM[][]
Posted:
Thu Apr 02, 2009 4:34 pm
by equinox
K, i try in this mode.
TNk1000 fro help.