sscanf
#1

How can I make sscanf see something that will make it understand it is separate?

Example:

A,B,C,D

How can I make sscanf recognize that the ',' is separating the letters?
Reply
#2

Use the 'p' specifier:
pawn Код:
"p<,>cccc"
Reply
#3

Okay and example how can I do this:

A,B,C,D | A,B,C,D

And make it recognize that one ABCD is different from another? With the p also?
Reply
#4

pawn Код:
"p<|>ss"
CMIIW
Reply
#5

No but I want it for example to separate each value with a ',' but then each line by a '|' or something similar, is that possible?
Reply
#6

Each line?
Reply
#7

The OP means A,B,C,D as a group of 4 single identifiers to be seperated
by (,) and then groups of identifiers to be seperated by (|).
Reply
#8

just combine Vince's and =WoR=Varth's string:
Код:
"p<,>cccc"
parse the A,B,C,D, then search for the | using the single quotes ' '
Код:
"p<,>cccc'|'"
and finally parse the next... E,F,G,H ?
Код:
"p<,>cccc'|'cccc"
Reply
#9

Umm but for example:

pawn Код:
#include <a_samp>

#define COLOR_BLUE 0x2641FEAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA

enum hInfo
{
    Float:hEntranceX,
    Float:hEntranceY,
    Float:hEntranceZ,
    Float:hEntranceA,
    Float:hExitX,
    Float:hExitY,
    Float:hExitZ,
    Float:hExitA,
    hOwner[MAX_PLAYER_NAME],
    hDescription[MAX_PLAYER_NAME],
    hValue,
    hRevenue,
    hHel,
    hArm,
    //
    nInt,
    //
    hInt,
    hWorld,
    hLock,
    hOwned,
    hRooms,
    hRent,
    hRentable,
    hPickup,
    //
    hSellprice,
};
new HouseInfo[1000][hInfo];

stock LoadHouse()
{
    new arrCoords[24][64];
    new szFileStr[1024],
    File: file = fopen("houses.cfg", io_read);
    if(file)
    {
        new idx;
        while(idx < sizeof(HouseInfo) && fread(file, szFileStr))
        {
            sscanf(szFileStr, "p<,>ffffffffs[126]s[126]dddddddddddddd");
            HouseInfo[idx][hEntranceX] = floatstr(arrCoords[0]);
            HouseInfo[idx][hEntranceY] = floatstr(arrCoords[1]);
            HouseInfo[idx][hEntranceZ] = floatstr(arrCoords[2]);
            HouseInfo[idx][hEntranceA] = floatstr(arrCoords[3]);
            HouseInfo[idx][hExitX] = floatstr(arrCoords[4]);
            HouseInfo[idx][hExitY] = floatstr(arrCoords[5]);
            HouseInfo[idx][hExitZ] = floatstr(arrCoords[6]);
            HouseInfo[idx][hExitA] = floatstr(arrCoords[7]);
            strmid(HouseInfo[idx][hOwner], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            strmid(HouseInfo[idx][hDescription], arrCoords[9], 0, strlen(arrCoords[9]), 255);
            HouseInfo[idx][hValue] = strval(arrCoords[10]);
            HouseInfo[idx][hRevenue] = strval(arrCoords[11]);
            HouseInfo[idx][hHel] = strval(arrCoords[12]);
            HouseInfo[idx][hArm] = strval(arrCoords[13]);
            HouseInfo[idx][nInt] = strval(arrCoords[14]);
            HouseInfo[idx][hInt] = strval(arrCoords[15]);
            HouseInfo[idx][hWorld] = strval(arrCoords[16]);
            HouseInfo[idx][hLock] = strval(arrCoords[17]);
            HouseInfo[idx][hOwned] = strval(arrCoords[18]);
            HouseInfo[idx][hRooms] = strval(arrCoords[19]);
            HouseInfo[idx][hRent] = strval(arrCoords[20]);
            HouseInfo[idx][hRentable] = strval(arrCoords[21]);
            HouseInfo[idx][hPickup] = strval(arrCoords[22]);
            HouseInfo[idx][hSellprice] = strval(arrCoords[23]);
            idx++;
        }
        for(new h = 0; h < sizeof(HouseInfo); h++)
        {
            if(HouseInfo[h][hOwned] == 0)
            {
                new string[126];
                format(string, sizeof(string), "Home For Sale \n Price: %d \n Type [/enter] To Go Inside", HouseInfo[h][hValue]);
                Create3DTextLabel(string, COLOR_RED, HouseInfo[h][hEntranceX], HouseInfo[h][hEntranceY], HouseInfo[h][hEntranceZ], 10, 0);
                HouseInfo[h][hPickup] = CreatePickup(1273,1,HouseInfo[h][hEntranceX],HouseInfo[h][hEntranceY],HouseInfo[h][hEntranceZ],0);
            }
            if(HouseInfo[h][hOwned] == 1)
            {
                new string[126];
                format(string, sizeof(string), "Home Owner: %s \n Locked: %d \n Type [/enter] To Go Inside", HouseInfo[h][hOwner], HouseInfo[h][hLock]);
                Create3DTextLabel(string, COLOR_GREEN, HouseInfo[h][hEntranceX], HouseInfo[h][hEntranceY], HouseInfo[h][hEntranceZ], 10, 0);
                HouseInfo[h][hPickup] = CreatePickup(1239,1,HouseInfo[h][hEntranceX],HouseInfo[h][hEntranceY],HouseInfo[h][hEntranceZ],0);
            }
        }
        print(" ");
        print("Dynamic Houses");
        print("---------------");
        fclose(file);
    }
    return 1;
}

stock SaveHouse()
{
    new idx;
    new File: file2;
    while (idx < sizeof(HouseInfo))
    {
        new coordsstring[128];
        format(coordsstring, sizeof(coordsstring), "%f,%f,%f,%f,%f,%f,%f,%f,%s,%s,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
        HouseInfo[idx][hEntranceX],
        HouseInfo[idx][hEntranceY],
        HouseInfo[idx][hEntranceZ],
        HouseInfo[idx][hEntranceA],
        HouseInfo[idx][hExitX],
        HouseInfo[idx][hExitY],
        HouseInfo[idx][hExitZ],
        HouseInfo[idx][hExitA],
        HouseInfo[idx][hOwner],
        HouseInfo[idx][hDescription],
        HouseInfo[idx][hValue],
        HouseInfo[idx][hRevenue],
        HouseInfo[idx][hHel],
        HouseInfo[idx][hArm],
        //
        HouseInfo[idx][nInt],
        //
        HouseInfo[idx][hInt],
        HouseInfo[idx][hWorld],
        HouseInfo[idx][hLock],
        HouseInfo[idx][hOwned],
        HouseInfo[idx][hRooms],
        HouseInfo[idx][hRent],
        HouseInfo[idx][hRentable],
        HouseInfo[idx][hPickup],
        //
        HouseInfo[idx][hSellprice]);
        if(idx == 0)
        {
            file2 = fopen("houses.cfg", io_write);
        }
        else
        {
            file2 = fopen("houses.cfg", io_append);
        }
        fwrite(file2, coordsstring);
        idx++;
        fclose(file2);
    }
    return 1;
}
The problem with that is, it doesn't load example one house string and then makes it work, it spawns the max houses, whether they are in "houses.cfg" or not and spawns them, how can I make it work, please help!
Reply
#10

the quickest way to track any weird behavior down, it to get a lot of debug printed out. i added some SendClientMessageToAll inside the sscanf, and nested the sscanf into a if(). if an invalid line gets read, it will show you ingame what it contains.
and it seems that the file is closed too early. pay attention to the if(file)...
Код:
stock LoadHouse()
{
	new arrCoords[24][64];
	new szFileStr[1024],
	File: file = fopen("houses.cfg", io_read);
	if(file)
	{
		new idx;
		while(idx < sizeof(HouseInfo) && fread(file, szFileStr)) 
		{
			if(sscanf(szFileStr, "p<,>ffffffffs[126]s[126]dddddddddddddd"))
			{
				SendClientMessageToAll(playerid,0xffff00ff,"1 invalid House parameter line detected:");
				SendClientMessageToAll(playerid,0xff7f00ff,szFileStr);
			}
			else
			{
				HouseInfo[idx][hEntranceX] = floatstr(arrCoords[0]);
				HouseInfo[idx][hEntranceY] = floatstr(arrCoords[1]);
				HouseInfo[idx][hEntranceZ] = floatstr(arrCoords[2]);
				HouseInfo[idx][hEntranceA] = floatstr(arrCoords[3]);
				HouseInfo[idx][hExitX] = floatstr(arrCoords[4]);
				HouseInfo[idx][hExitY] = floatstr(arrCoords[5]);
				HouseInfo[idx][hExitZ] = floatstr(arrCoords[6]);
				HouseInfo[idx][hExitA] = floatstr(arrCoords[7]);
				strmid(HouseInfo[idx][hOwner], arrCoords[8], 0, strlen(arrCoords[8]), 255);
				strmid(HouseInfo[idx][hDescription], arrCoords[9], 0, strlen(arrCoords[9]), 255);
				HouseInfo[idx][hValue] = strval(arrCoords[10]);
				HouseInfo[idx][hRevenue] = strval(arrCoords[11]);
				HouseInfo[idx][hHel] = strval(arrCoords[12]);
				HouseInfo[idx][hArm] = strval(arrCoords[13]);
				HouseInfo[idx][nInt] = strval(arrCoords[14]);
				HouseInfo[idx][hInt] = strval(arrCoords[15]);
				HouseInfo[idx][hWorld] = strval(arrCoords[16]);
				HouseInfo[idx][hLock] = strval(arrCoords[17]);
				HouseInfo[idx][hOwned] = strval(arrCoords[18]);
				HouseInfo[idx][hRooms] = strval(arrCoords[19]);
				HouseInfo[idx][hRent] = strval(arrCoords[20]);
				HouseInfo[idx][hRentable] = strval(arrCoords[21]);
				HouseInfo[idx][hPickup] = strval(arrCoords[22]);
				HouseInfo[idx][hSellprice] = strval(arrCoords[23]);
				idx++;
				SendClientMessageToAll(playerid,0xffff00ff,"1 Valid House Loaded");
			}
		}
		for(new h = 0; h < sizeof(HouseInfo); h++)
		{
			if(HouseInfo[h][hOwned] == 0)
			{
				new string[126];
				format(string, sizeof(string), "Home For Sale \n Price: %d \n Type [/enter] To Go Inside", HouseInfo[h][hValue]);
				Create3DTextLabel(string, COLOR_RED, HouseInfo[h][hEntranceX], HouseInfo[h][hEntranceY], HouseInfo[h][hEntranceZ], 10, 0);
				HouseInfo[h][hPickup] = CreatePickup(1273,1,HouseInfo[h][hEntranceX],HouseInfo[h][hEntranceY],HouseInfo[h][hEntranceZ],0);
			}
			if(HouseInfo[h][hOwned] == 1)
			{
				new string[126];
				format(string, sizeof(string), "Home Owner: %s \n Locked: %d \n Type [/enter] To Go Inside", HouseInfo[h][hOwner], HouseInfo[h][hLock]);
				Create3DTextLabel(string, COLOR_GREEN, HouseInfo[h][hEntranceX], HouseInfo[h][hEntranceY], HouseInfo[h][hEntranceZ], 10, 0);
				HouseInfo[h][hPickup] = CreatePickup(1239,1,HouseInfo[h][hEntranceX],HouseInfo[h][hEntranceY],HouseInfo[h][hEntranceZ],0);
			}
		}
	}
	fclose(file); //i put that down 1 }bracket
	print(" ");
	print("Dynamic Houses");
	print("---------------");
	return 1;
}
i cant test that out, so i did only easy stuff for debugging. its a good idea to backup all house files, and work with a "limited" version, like 3-4 houses only, all created by hand... good luck!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)