noob question about sizeof()
#1

hello

I know it is wrong, but how I do it right?

PHP код:
sizeof(VehicleInfo[vehicleid][vPlaca]) 
PHP код:
forward SetVehicleNumberPlateEx(vehicleidnumberplate[]);
public 
SetVehicleNumberPlateEx(vehicleidnumberplate[])
{
    
format(VehicleInfo[vehicleid][vPlaca], sizeof(VehicleInfo[vehicleid][vPlaca]), "%s"numberplate);
    
SetVehicleNumberPlate(vehicleidVehicleInfo[vehicleid][vPlaca]);

Reply
#2

This is the correct way of doing it.
Reply
#3

Can't be reliably retrieved. Put the number itself or a definition instead.
Reply
#4

Just enter its size.
Also, you should use strcpy for this, not format.
pawn Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)

strcpy(VehicleInfo[vehicleid][vPlaca], numberplate, SIZE HERE);
Reply
#5

Quote:
Originally Posted by Mionee
Посмотреть сообщение
This is the correct way of doing it.
no, it's not.
the following error is returned:
Quote:

BSL2.pwn(2603) : error 001: expected token: "]", but found "-identifier-"
BSL2.pwn(2603) : warning 215: expression has no effect
BSL2.pwn(2603) : error 001: expected token: ";", but found "]"
BSL2.pwn(2603) : error 029: invalid expression, assumed zero
BSL2.pwn(2603) : fatal error 107: too many error messages on one line

Quote:
Originally Posted by Vince
Посмотреть сообщение
Can't be reliably retrieved. Put the number itself or a definition instead.
are you sure?
It's so sad ;(
Reply
#6

Quote:
Originally Posted by dudaefj
Посмотреть сообщение
are you sure?
It's so sad ;(
Yes. For a regular array, the correct way of doing it would be:
pawn Код:
sizeof(array[])
// or
sizeof(array[][])
But since this concerns an enum, I have no idea what size would be returned. I suppose it'd be the largest one. So if you have something like:
pawn Код:
enum myVars {
    string1[64],
    plate[16]
}
There'd be a good chance that it'd return 64, which is not what you want.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)