Quote:
Originally Posted by Kraeror
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 код:
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;
}
|
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]+$"