sscanf to explode
#1

Hello! I've got several problems with sscanf, and I would like to move on explode system, but I don't really know how. It's my load player data script, and as "my.username" was last to load there was several problems with showing forumID. Now when I put it in first slot there's a problem with sscanfing forumName. If I've got a nicknames like: Bobs, Robbers, IgrexolonO it will show like this: B bs, R bbers, I rexolonO. There's always a space at 2nd character (but the mysql_store_result() is fine (debug)):

Return: MexikanoS|1|1|4|999|800|200|488.3582|-1880.8929|15.3423|327.1967|0|0|0|0|0|0|0|0|0|0|0|0

So now, here goes the code

Код:
	format(sqlquery, sizeof(sqlquery), "SELECT my.username, p.gid, p.forumID, p.adminLvl, p.skin, p.money, p.bMoney, p.lastPosX, p.lastPosY, p.lastPosZ, p.lastPosAngle, p.item_1, p.item_2, p.item_3, p.item_4, p.item_5, p.item_6, p.item_7, p.item_8, p.item_9, p.item_10, p.item_11, p.item_12 FROM players p LEFT JOIN mybb_users my ON (p.forumID = my.uid) WHERE `login`='%s'", pName_(pid));
	mysql_query(sqlquery);
	mysql_store_result();
	while(mysql_fetch_row_format(sqlstring, "|"))
	{
		printf(sqlstring);		
		
		mysql_fetch_field_row(playerInfo[pid][forumName], "my.username");
		printf("%s", playerInfo[pid][forumName]);
	
		sscanf(sqlstring, "p<|>s[24]iiiiiiffffiiiiiiiiiiii",
			playerInfo[pid][forumName],
			playerInfo[pid][gid],
			playerInfo[pid][forumID],
			playerInfo[pid][adminLvl],
			playerInfo[pid][skin],
			playerInfo[pid][money],
			playerInfo[pid][bMoney],
			playerInfo[pid][lastPos][0],
			playerInfo[pid][lastPos][1],
			playerInfo[pid][lastPos][2],
			playerInfo[pid][lastPos][3],
			playerInfo[pid][item][0],
			playerInfo[pid][item][1],
			playerInfo[pid][item][2],
			playerInfo[pid][item][3],
			playerInfo[pid][item][4],
			playerInfo[pid][item][5],
			playerInfo[pid][item][6],
			playerInfo[pid][item][7],
			playerInfo[pid][item][8],
			playerInfo[pid][item][9],
			playerInfo[pid][item][10],
			playerInfo[pid][item][11]);
	}
And I have no idea how to rewrite it to explode. https://sampforum.blast.hk/showthread.php?tid=223561 I just found out this tutorial, but I still don't really know, how to properly use it. Could somebody help me?

Regards.
Reply
#2

did you heard about the "tag" (?) e (enum) in sscanf?
Reply
#3

Naa, I don't. Give me an example or kkthx.
Reply
#4

PHP код:
enum
    E_DATA
{
    
E_DATA_C,
    
Float:E_DATA_X,
    
E_DATA_NAME[32],
    
E_DATA_Z
}
main
{
    new
        var[
E_DATA];
    
sscanf("1 12.0 Bob c""e<ifs[32]c>", var);

Reply
#5

Код:
enum pInfo
{
	gid,
	forumName,
	forumID,
	pass[20],
	logInChances,
	ip[16],
	adminLvl,
	bool:loggedIn,
	money,
	bMoney,
	skin,
	fraction[3],
	Float:lastPos[4],
	lastPosInt,
	lastPosVW,
	bool:frozen,
	specMode[2],
	useAnim,
	bool:cuffied,
	onlineTimeStarted,
	onlineTime,
	togPM,
	Text3D:nickLabel,
	doorEdit[2],
	aflyMode[2],
	vehBeingDrived[2],
	item[MAX_PLAYER_ITEMS],
	searchedItems[MAX_PLAYER_ITEMS],
	choosedFromSearch,
	choosedFromSearchActivity,
	vPanelID,
	vCreateModel,
	Float:sp[4],
	Float:oldVehicleHealth,
	Float:newVehicleHealth,
	antyCheatVariables[2],
	skillsy[2]
}; new playerInfo[MAX_PLAYERS][pInfo];
So have fun, that I would do this by your way.
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
You realise that "explode" is a massive downgrade from sscanf right? And if it is fun, why not do it? That way is vastly simpler than your way.
The only problem is, that I'm not filling every single enum. So how can I do it?
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
"Minus" specifiers - see the documentation in the first post of the sscanf topic.
But now tell me one little thing. Why my code won't work properly?
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
I don't know, what have you written since?
I mean why my old code won't work properly..

#First post, please take a look. It's doing a space in a 2nd character of forumName.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)