Function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Function (
/showthread.php?tid=254177)
Function - Unknown123 - 09.05.2011
Код:
if(IsValidText("Hi there")) return SendClientMessage(playerid, 0xFF0000FF, "Valid Text"); // Correct
if(IsValidText(":> Hello There")) return SendClientMessage(playerid, 0xFF0000FF, "Invailid Text"); // Correct
if(IsValidText("Hello :> There")) return SendClientMessage(playerid, 0xFF0000FF, "Vailid Text"); // Wrong
pawn Код:
stock IsValidText(text[])
{
for(new i = 0; i < sizeof(text[]); i++)
{
if(text[i] == 'a' || text[i] == 'b' || text[i] == 'c' || text[i] == 'd'
|| text[i] == 'e' || text[i] == 'f' || text[i] == 'g' || text[i] == 'h'
|| text[i] == 'i' || text[i] == 'j' || text[i] == 'k' || text[i] == 'l'
|| text[i] == 'm' || text[i] == 'n' || text[i] == 'o' || text[i] == 'p'
|| text[i] == 'q' || text[i] == 'r' || text[i] == 's' || text[i] == 't'
|| text[i] == 'u' || text[i] == 'v' || text[i] == 'w' || text[i] == 'x'
|| text[i] == 'y' || text[i] == 'z')
return 1;
}
return 0;
}
Re: Function -
Sascha - 09.05.2011
for(new i = 0; i < sizeof(text); i++)
however I guess that's not the actual problem
Re: Function -
MadeMan - 09.05.2011
pawn Код:
stock IsValidText(text[])
{
for(new i = 0; text[i]; i++)
{
if(text[i] != 'a' && text[i] != 'b' && text[i] != 'c' && text[i] != 'd'
&& text[i] != 'e' && text[i] != 'f' && text[i] != 'g' && text[i] != 'h'
&& text[i] != 'i' && text[i] != 'j' && text[i] != 'k' && text[i] != 'l'
&& text[i] != 'm' && text[i] != 'n' && text[i] != 'o' && text[i] != 'p'
&& text[i] != 'q' && text[i] != 'r' && text[i] != 's' && text[i] != 't'
&& text[i] != 'u' && text[i] != 'v' && text[i] != 'w' && text[i] != 'x'
&& text[i] != 'y' && text[i] != 'z')
return 0;
}
return 1;
}
Re: Function -
Sascha - 09.05.2011
won't that be an endless loop?
Re: Function -
Vince - 09.05.2011
pawn Код:
stock IsValidText(const text[])
{
for(new i = 0; i < sizeof(text); i++)
if(!('A' <= text[i] <= 'Z') && !('a' <= text[i] <= 'z')) return 0;
return 1;
}
ASCII table:
http://www.asciitable.com/index/asciifull.gif
Re: Function - Unknown123 - 09.05.2011
pawn Код:
indeterminate array size in "sizeof" expression (symbol "")
if i change
pawn Код:
for(new i = 0; i < sizeof(text); i++)
to
pawn Код:
for(new i = 0; i < sizeof(text[]); i++)
i will repove the warning but i will get save bug at my 1 post
Re: Function -
Vince - 09.05.2011
Sorry, this one should work. Tested it.
pawn Код:
IsValidText(const text[])
{
for(new i = 0, j = strlen(text); i < j; i++)
if(!('A' <= text[i] <= 'Z') && !('a' <= text[i] <= 'z')) return 0;
return 1;
}
Re: Function -
MadeMan - 09.05.2011
Quote:
Originally Posted by Sascha
won't that be an endless loop?
|
No, it will stop when reached to the end of the string.
Doing
pawn Код:
for(new i = 0; text[i]; i++)
is same as
pawn Код:
for(new i = 0; text[i] != 0; i++)
same as
pawn Код:
for(new i = 0; text[i] != EOS; i++)
same as
pawn Код:
for(new i = 0; text[i] != '\0'; i++)