sscanf kustom specifiers and space
#1

Hello, i have a sscanf custom specifiers to check if gang name is exists.
Here is my code:
Код:
SSCANF:gang(string[])
{
	printf("SSCANF:gang string is \"%s\"", string);
	new ret;
	if ('0' <= string[0] <= '9')
	{
		ret = strval(string);
		if(Iter_Contains(Gangs, ret))
			return ret;
	}

	foreach(new i : Gangs)
	{
		if(!strcmp(g_Gang[i][gname], string, true))
			return i;
	}
	return -1;
}
The problem is, it doesn't work while i'm trying to find a gang that have spaces in it.
I've debugged that code by printing "string" variable, and i found out that the string is getting cut off at space.

Код:
new testname[12] = "Gang name", id;
sscanf(testname, "k<gang>", id); // Prints SSCANF:gang string is "Gang"
testname = "Gang_name";
sscanf(testname, "k<gang>", id); // Prints SSCANF:gang string is "Gang_name"
Is there any way to fix this / to make it works?
Thanks in advance.
Reply
#2

Just use Group_GetID method;

Код:
if(Group_GetID(string) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
Reply
#3

Quote:
Originally Posted by justice96
Посмотреть сообщение
Just use Group_GetID method;

Код:
if(Group_GetID(string) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
I didn't use y_group. However, thanks for the answer, i may use y_group in future.
Reply
#4

Quote:
Originally Posted by X337
Посмотреть сообщение
I didn't use y_group. However, thanks for the answer, i may use y_group in future.
Remember that, you can also defined a variable gang for player;

Код:
new gangid = PlayerInGang[playerid];
if(Group_GetID(gangid) != INVALID_GROUP) return SendClientMessage(playerid, -1, "ERROR: Gang name already exists!");
or you can loop each Gangs through foreach/Iter
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)