help with sscanf
#1

I'm trying to load the information from the database to the enumeration vehicleinfo with sscanf but it doesnt print the Licenses etc. What I am doing wrong? Thank's in advance.
pawn Код:
stock LoadVehicleID(vehicleid, playerid)
{
    new query[1021];
    format(query, sizeof(query), " SELECT * FROM vehicles WHERE id= %d", vehicleid);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows())
    if(mysql_fetch_row(query))
    {
        sscanf(query, "p<|>e<iiiiffffs[25]s[25]iiiii>", vehicleinfo[vehicleid]);
        vkey[playerid] = CreateVehicle(vehicleinfo[vehicleid][Model],vehicleinfo[vehicleid][x],vehicleinfo[vehicleid][y],vehicleinfo[vehicleid][z],vehicleinfo[vehicleid][a],vehicleinfo[vehicleid][Color1],vehicleinfo[vehicleid][Color2], 60*10000);
        printf("result: %d",vkey[playerid]);
        printf("lock = %d  pawked = %d spawned %d destroyed %d liceneses %d",
        vehicleinfo[vehicleid][Lock],
        vehicleinfo[vehicleid][Parked],
        vehicleinfo[vehicleid][Spawned],
        vehicleinfo[vehicleid][Destroyed],
        vehicleinfo[vehicleid][Licenses]);
    }  
}
Reply
#2

Quote:

[18:09:20] lock = 0 pawked = 0 spawned 1 destroyed 1 liceneses 0

here is the print.
Reply
#3

Quote:
[08:36:10] query: 12|411|0|0|340.81253|-1345.224609|14.234893|118.757064|infernus|Mark|1|1 |0|2|3
[08:36:10] lock = 0 pawked = 0 spawned 1 destroyed 1 liceneses 0

Thats the query and the print of the variables also im gonna show the enumeration:
pawn Код:
enum vInfo()
{
    id,
    Model,
    Color1,
    Color2,
    Float:x,
    Float:y,
    Float:z,
    Float:a,
    Name[MAX_PLAYER_NAME],
    Owner[MAX_PLAYER_NAME],
    Lock,
    Parked,
    Spawned,
    Destroyed,
    Licenses,
}
new vehicleinfo[MAX_VEHICLES][vInfo];
Reply
#4

Is the sscanf plugin buged?
Reply
#5

Someone can help me with this?
Reply
#6

pawn Код:
if(mysql_num_rows())
if(mysql_fetch_row(query))
{
This doesn't look good

Is for example the Name field correctly fetched?
Reply
#7

The problem is with the plugin because the print of the query is showing everything alright.
Reply
#8

Ok, now this is just weird - MAX_PLAYER_NAME is 24, yup? So s[25] should suffice, yup? BUT current code causes runtime error for me - why? No idea - probably stack corruption or something. So I changed it to 26 - no dice, owner wasn't loaded. So I tried 24, and guess what:



Now - it works, but I have no idea what will happen if the name will be 24 characters long (so in fact 24 + \0 NUL).
Reply
#9

Thanks Misiur it worked, the problem was with the strings!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)