how to get the amount?
#1

hi..
I'm having a little problem..
I have this array:
pawn Код:
enum Texts
{
  maAR[10],
  maRAY[50]
}
new MyArray[][][Texts] =
{
  {
    {"Hello", "This is an example"}
  },
  {
    {"Hmm", "Hello again"}
  }
};
and now I have this code
pawn Код:
for(new n=0; n<sizeof(MyArray[0]); n++)
  {
    if(n == 0)
      format(string, sizeof(string), "%s", MyArray[0][n][maAR]);
    else
      format(string, sizeof(string), "%s\n%s", string, MyArray[0][n][maAR]);
  }
which returns this error (on the "for new n=0 ....." line)
Код:
error 001: expected token: "]", but found "-integer value-"
error 029: invalid expression, assumed zero
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
so any ideas how to fix this?
(note, yes I need 3 dimensions in the array and no I will not change this..)
Am I doing the sizeof part wrong? 'cause that's how I would think it would work...
Reply
#2

pawn Код:
new MyArray[][][Texts] =
{
    {"Hello", "This is an example"},
    {"Hmm", "Hello again"}
};
Reply
#3

that would be "MyArray[][Texts]" then


the problem is within the loop I guess... the array itself should be correct

the sizeof doesn't work the way I used it..
Reply
#4

sorry for bumping, although... anyone please?
Reply
#5

Sizeof gets the size of the first dimension.
Reply
#6

Try
pawn Код:
sizeof(MyArray[]);
Reply
#7

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Sizeof gets the size of the first dimension.
orly? already knew that lol..

anyways for the sizeof(MyArray[]);.. it doesn't work either.. (can't actually work as each first dimension has different amounts of second dimensions)

any other advice?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)