SA-MP Forums Archive
[Ajuda] Checagem tamanho maximo string - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Português/Portuguese (https://sampforum.blast.hk/forumdisplay.php?fid=34)
+---- Thread: [Ajuda] Checagem tamanho maximo string (/showthread.php?tid=628854)



Checagem tamanho maximo string - maikons - 16.02.2017

Como fazer isso:
Код:
if(name maior que 30 caracters) return SendClientMessage(playerid, -1, "The name can not have more then 30 caracters");
Pra esse cуdigo:
Код:
CMD:createbizz(playerid, params[]) {
	new bizzid, name[30], type;
	if(sscanf(params,"ii", bizzid, type, name)) {
		SendClientMessage(playerid, -1, "Use: /createbizz [id] [type] [name]");
		return 1;
	}
	if(bizzid < 1 && bizzid > MAX_BIZZ) return SendClientMessage(playerid, -1, "Choose a number between 1-MAX_HOUSES");

	// como fazer isso?
	if(name maior que 30 caracters) return SendClientMessage(playerid, -1, "The name can not have more then 30 caracters");

	return 1;
}



Re: Checagem tamanho maximo string - Whoo - 16.02.2017

strlen para saber o tamanho de uma string..

Код:
if(strlen(name) > 30) {..}



Re: Checagem tamanho maximo string - Showzs - 16.02.2017

PHP код:
if( name 30 ) return SendClientMessageplayerid, -1"The name can not have more then 30 caracters" ); 



Re: Checagem tamanho maximo string - LockedLucas - 16.02.2017

Quote:
Originally Posted by Showzs
Посмотреть сообщение
PHP код:
if( name 30 ) return SendClientMessageplayerid, -1"The name can not have more then 30 caracters" ); 
Errado, o que o Whoo disse, й o certo.


Re: Checagem tamanho maximo string - willttoonn - 16.02.2017

Tente dessa forma:

Код:
CMD:createbizz(playerid, params[]) {
	new bizzid, name[30], type;
	if(sscanf(params,"dds[30]", bizzid, type, name)) {
		SendClientMessage(playerid, -1, "Use: /createbizz [id] [type] [name]");
		return 1;
	}
	if(bizzid < 1 && bizzid > MAX_BIZZ) return SendClientMessage(playerid, -1, "Choose a number between 1-MAX_HOUSES");

	// como fazer isso?
	if(strlen(name) > 30) return SendClientMessage(playerid, -1, "The name can not have more then 30 caracters");

	return 1;
}



Re: Checagem tamanho maximo string - maikons - 21.02.2017

escrevi tudo errado...


Re: Checagem tamanho maximo string - maikons - 22.02.2017

Nunca pega nessa return SendClientMessage(playerid, -1, "The name can not have more then 30 caracters");
Код:
if(strlen(name) > 30) return SendClientMessage(playerid, -1, "The name can not have more then 30 caracters");
Mesmo que eu escreva /createbizz 1 1 Odskoakdosakodksaokxoak2o3kodkoakdsa2

Pega sу uma parte do nome escrito...


Re: Checagem tamanho maximo string - MultiKill - 22.02.2017

Код:
if(sscanf(params,"iis[30]", bizzid, type, name)) {



Re: Checagem tamanho maximo string - maikons - 23.02.2017

Quote:
Originally Posted by MultiKill
Посмотреть сообщение
Код:
if(sscanf(params,"iis[30]", bizzid, type, name)) {
Ah entгo esse
s[30]

Que eu coloquei jб limita automaticamente pra 30 e qnd passa corta?


Re: Checagem tamanho maximo string - MultiKill - 23.02.2017

Vocк pode limitar o nъmero de caracteres assim ou sу passar o limite da string, na ultima versгo deve-se passar o tamanho da string se nгo fizer isso vai gerar um aviso na hora da execuзгo do cуdigo.

Como no seu comando a string name contйm 30 cйlulas sendo o нndice 29 o EOS (end of string) o nъmero mбximo de caracteres suportados й de 29 entгo nunca vai entrar no retorno da mensagem enviada da verificaзгo do tamanho da string. Por isso vocк pode passar um nome com 100 caracteres e nunca vai retornar a mensagem enviada, pois caso o nome passado pelo sscanf for maior que 29 sempre vai ser 29 e nгo 30.