08.12.2018, 12:55
Quote:
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 код:
|
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;
}