bool:OnlyLetters(playerid, const text[])
{
new chars = 1;
for(new i = 'a'; i <= 'z'; i++)
{
new string[256];
format(string, sizeof(string), "%c", i);
for(new l = 0; l <= strlen(text); l++)
{
if(strfind(text[l], string, false)) chars++;
}
format(string, sizeof(string), "%d, %d", chars, strlen(text));
SendClientMessage(playerid, COLOR_RED, string);
if(chars != strlen(text)) return false;
else return true;
}
return false;
}
hello ello llo lo o
i = -1
WHILE string[++i] do
IF NOT('a'<=string[i]<='z') AND NOT('A'<=string[i]<='Z') then
RETURN FALSE
ENDIF
ENDWHILE
RETURN TRUE
What you doing here is
selects a to z characters one by one.On each step you are stroing this single character to a string.Then starts another iteration from beginning of the passed string text to it's end.Then you are passing from the "l"th index of text and characters from a to z (string)to strfind.So if "hello" is the text[] each time (in l loop) you are passing following to strfind Код:
hello ello llo lo o strfind returns the number of characters before the sub string (the sub string's start position) or -1 if it's not found. (from wiki) Therefore clearly the counting variable chars wont have number you are expecting What you can possibly do is start from 0th index of the string to it's end and check if the character is an non alphabetic character if yes stop the program flow and return false and if iteration completes return true PHP код:
|
bool:OnlyLetters(const text[])
{
new chars = strlen(text)+1;
for(new i = 'a'; i <= 'z'; i++)
{
new string[256];
format(string, sizeof(string), "%c", i);
for(new l = 0; l <= strlen(text); l++)
{
if(strcmp(text[l], " ", true) == 1)
if(strcmp(text[l], string, true) == 1){} else chars--;
}
if(chars != strlen(text)) return false;
else return true;
}
return false;
}
I have just fixed my code, I did really stupid mistakes, so thanks for your help, but I did it myself. I'm still learning
Here is how I fixed it: PHP код:
|
That code won't work.You are over complicating your code.There's no need for that string variable itself and the outer loop iterates only once.A string is collection or array of characters.You can check each character one by one and check if it is not alphabet(as i mentioned in pseudo code in above post).Or just use regular expression "^[A-Za-z]+$"
|
C:\Users\Dakzde\Desktop\Servers and Sites\Bulgarian Server\gamemodes\BG.pwn(51) : error 001: expected token: ";", but found "-identifier-" C:\Users\Dakzde\Desktop\Servers and Sites\Bulgarian Server\gamemodes\BG.pwn(51) : error 017: undefined symbol "WHILE" C:\Users\Dakzde\Desktop\Servers and Sites\Bulgarian Server\gamemodes\BG.pwn(51) : error 017: undefined symbol "string" C:\Users\Dakzde\Desktop\Servers and Sites\Bulgarian Server\gamemodes\BG.pwn(51) : fatal error 107: too many error messages on one line |
WHILE string[++i] do
I checked your code and:
Error line: PHP код:
|