Weird Problem about Arrays !!! Somebody tell me what's going on please..
#1

Код:
(3597) : error 047: array sizes do not match, or destination array is too small
(3598) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
pawn Код:
enum Houses
{
    HouseName[64],
    HouseOwner[64],
    HouseLocation[64],
}
new HouseInfo[MAX_HOUSES][Houses];

//These scripts are the errors:
HouseInfo[h][HouseName] = "Unowned House";
HouseInfo[h][HouseOwner] = "Nobody";
Somebody tell me why are these codes giving me errors ? And why it got fixed if i make the codes like:
pawn Код:
new str[64];
format(str, sizeof(str), "Unowned House");
HouseInfo[h][HouseName] = str;
format(str, sizeof(str), "Nobody");
HouseInfo[h][HouseOwner] = str;
Reply
#2

destination array is too small...
Reply
#3

Код:
new HouseInfo[MAX_HOUSES][Houses];
Код:
HouseInfo[h][HouseName] = "Unowned House";
The "h" in the second code, shouldn't it be "HouseInfo?

Anyways, your array sizes are too small, if you make it a bit bigger, then it should solve the problem.
Reply
#4

Quote:
Originally Posted by Juvanii
Посмотреть сообщение
pawn Код:
new str[64];
format(str, sizeof(str), "Unowned House");
HouseInfo[h][HouseName] = str; // will not work
format(str, sizeof(str), "Nobody");
HouseInfo[h][HouseOwner] = str; // will not work
pawn Код:
format(HouseInfo[h][HouseName], 64, "Unowned House"); // work
format(HouseInfo[h][HouseOwner], 64, "Nobody"); // work
Otherwise there is the method of the nag :
pawn Код:
HouseInfo[h][HouseOwner][0] = 'N';
HouseInfo[h][HouseOwner][1] = 'o';
HouseInfo[h][HouseOwner][2] = 'b';
HouseInfo[h][HouseOwner][4] = 'o';
HouseInfo[h][HouseOwner][5] = 'd';
HouseInfo[h][HouseOwner][6] = 'y';

printf("%s", HouseInfo[h][HouseOwner]); // show "Nobody"
Reply
#5

Код:
strmid(HouseInfo[h][HouseOwner], "Nobody", 0, strlen("Nobody"), 255);
Код:
strmid(HouseInfo[h][HouseName], "Unowned House", 0, strlen("Nobody"), 255);
Reply
#6

Let me tell you why you have those errors:

Let us start out with analyzing your first code:

pawn Код:
enum Houses
{
    HouseName[64],
    HouseOwner[64],
    HouseLocation[64],
}
new HouseInfo[MAX_HOUSES][Houses];

//These scripts are the errors:
HouseInfo[h][HouseName] = "Unowned House";
HouseInfo[h][HouseOwner] = "Nobody";
If you look at the first error line in your code submitted above, you will see that you defined "HouseName" to have a length of 64. That means 63 letters/slots available (including the null terminating the string). In that first error line, the "string" is not matching the size of the "HouseName". The string you wrote is the same defining the lenght as 14. So, that means: 64 and 14 does not match do they? That is what the error tells you.


So, If you write:

pawn Код:
new str[64];
format(str, sizeof(str), "Unowned House");
HouseInfo[h][HouseName] = str;
format(str, sizeof(str), "Nobody");
You define a string with 64 slots (which is the same size as f.ex the "HouseName"). When you "format" something, you just replace characters in the pre-defined string with the ones you want:

Before formatting:
pawn Код:
//str:
str[0] --> \0
str[1] --> \0
str[2] --> \0
str[3] --> \0
str[4] --> \0
str[5] --> \0
str[6] --> \0
str[7] --> \0
str[8] --> \0
str[9] --> \0
str[10] --> \0
str[11] --> \0
str[12] --> \0
str[13] --> \0
str[14] --> \0
...
str[63] --> \0
After formatting:
pawn Код:
//str after formatting it:
str[0] -->U
str[1] -->n
str[2] -->o
str[3] -->w
str[4] -->n
str[5] -->e
str[6] -->d
str[7] -->
str[8] -->h
str[9] -->o
str[10] -->u
str[11] -->s
str[12] -->e
str[13] -->\0
str[14] -->\0
...
str[63] -->\0

That makes the strings match, and you don't get any errors-


I might have a few mistakes, but i really hope you get the point. That is the difference doing what you did without formatting and the one where you formatted.

Greetings
Reply
#7

Guys i have the same way to make a 'text variable' in other enums and works great, i really don't know what's goin on, it is confusing me all the time.
Reply
#8

Sorry for bump this up again, i just don't have to make a new thread while there is one already exist about this subject.
****** i just wanna know why there are no errors on compiling when you store 'text data' in a variable which is defined by this way:


pawn Код:
// Defining:
new Variable[MAX_PLAYERS][64];

//Somewhere:
Variable[playerid] = "Something";
// Compile: No Errors.
And you got the error if you define the variable by this way:
pawn Код:
//Defining:
enum test
{
    Variable[64]
}
new Info[MAX_PLAYERS][test];

//Somewhere:
Info[playerid][Variable] = "Something";
// Compile: error 047: array sizes do not match, or destination array is too small
i started with a blank page in pawno and tried it, same error. So there are no mistakes in my current scripts.
Anybody would please explain what's goin on?
Reply
#9

nevermind i just store the data by formatting.
pawn Код:
format(Info[playerid][Variable], 64, "Data")
Reply
#10

Quote:
Originally Posted by Juvanii
Посмотреть сообщение
nevermind i just store the data by formatting.
pawn Код:
format(Info[playerid][Variable], 64, "Data")
You could read what i wrote to you above, in order to understand what formatting does.

That's probably exactly the same i stated in my first post here :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)