anoing strlen stop at 31
#1

hi everybody... i have this code:

Код:
CMD:anunt(playerid, params[])
{
	new text[128],anunt[128],nume_jucator[24];
	GetPlayerName(playerid, nume_jucator, sizeof(nume_jucator));
    if(sscanf(params,"s", text)) return SendClientMessage(playerid, 0xFF0000FF,"Comanda gresita. Corect este: /anunt [text]");
    if(factiune[playerid] == 2)
        {
            if(duty[playerid] == 1)
                {
					new lungime_text = strlen(text);
					new lungime_nume = strlen(nume_jucator);
					new lungime_titlu = strlen("Reporter: : ");
					new lungime_ramasa = 128 - lungime_titlu - lungime_nume;
					if(lungime_text <= lungime_ramasa)
					    {
				            format(anunt,sizeof(anunt), "Reporter: %s: lungime text:%i, lungime nume:%i, lungime titlu: %i, lungime ramasa:%i",nume_jucator,lungime_text,lungime_nume,lungime_titlu,lungime_ramasa);
				            for(new i=0; i <= MAX_PLAYERS; i++)
				                {
									SendClientMessage(i,0xffa500ff, anunt);
				                }
						}
					else
					    {
					        SendClientMessage(playerid, 0xFF0000FF,"Textul tau nu incape pe un rand.");
					    }
				}
			else
			    {
			        SendClientMessage(playerid, 0xFF0000FF,"Trebuie sa fii on duty ca sa poti da anunturi.");
			    }
        }
	else
	    {
	        SendClientMessage(playerid, 0xFF0000FF,"Trebuie sa fii reporter ca sa poti da anunturi.");
	    }

	return 1;
}
and if i enter 27 caracters it say me 27, 28-28,29-29,30-30,31-31, but if i entered 32+ it say me that i entered 31 why?

[ame]http://www.youtube.com/watch?v=wJavnE0Y21o[/ame]
Reply
#2

pawn Код:
if(sscanf(params,"s", text)) return SendClientMessage(playerid, 0xFF0000FF,"Comanda gresita. Corect este: /anunt [text]");
https://github.com/Y-Less/sscanf/wiki/%22s%22-Specifier

You must specify the length of the string you're attempting to get. Try:

pawn Код:
if(sscanf(params,"s[128]", text)) return SendClientMessage(playerid, 0xFF0000FF,"Comanda gresita. Corect este: /anunt [text]");
Also, why don't you use SendClientMessageToAll instead of
pawn Код:
for(new i=0; i <= MAX_PLAYERS; i++)
                                {
                                    SendClientMessage(i,0xffa500ff, anunt);
                                }
? https://sampwiki.blast.hk/wiki/SendClientMessageToAll
Reply
#3

Now works but i have a another question why all time lungime_ramasa is 102?

Код:
new lungime_text = strlen(text);
					new lungime_nume = strlen(nume_jucator);
					new lungime_titlu = strlen("Reporter: : ");
					new lungime_ramasa = 128 - lungime_titlu - lungime_nume;
Reply
#4

Because "lungime_ramasa" has the value of the equation "128 - strlen("Reporter: : ") - strlen(nume_jucator)".

That means 128 - 12= 116 - strlen(nume_jucator) wich is the name of the player who uses this command. So if your name has the length 14 it will always give 102 IF YOU are using this command. Try using this command from an account with a different name so you'll ses another lungime_ramasa value.
Reply
#5

oh.... yes i now see i have a verry hard day with 2 exams... i used lungime_ramasa for know how manny letter less without text , i mean that it is how manny letter less with text .... sorry my bad


Thank you very much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)