strfind
#3

Quote:
Originally Posted by SyS
Посмотреть сообщение
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
Also
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 код:
= -
WHILE string[++i] do 
    IF 
NOT('a'<=string[i]<='z') OR NOT('A'<=string[i]<='Z'then
        
RETURN FALSE
    
ENDIF
ENDWHILE
RETURN 
TRUE 
Though,more easier method would be using regex
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 
'a'<= 'z'i++)
    {
        new 
string[256];
          
format(stringsizeof(string), "%c"i);
        for(new 
0<= strlen(text); l++)
        {
            if(
strcmp(text[l], " "true) == 1)
            if(
strcmp(text[l], stringtrue) == 1){} else chars--;
        }
        if(
chars != strlen(text)) return false;
        else return 
true;
    }
    return 
false;

Reply


Messages In This Thread
strfind - by Kraeror - 08.12.2018, 12:26
Re: strfind - by SyS - 08.12.2018, 12:51
Re: strfind - by Kraeror - 08.12.2018, 12:55
Re: strfind - by SyS - 08.12.2018, 13:08
Re: strfind - by Kraeror - 08.12.2018, 15:38
Re: strfind - by SyS - 08.12.2018, 15:46
Re: strfind - by Kraeror - 08.12.2018, 19:10

Forum Jump:


Users browsing this thread: 1 Guest(s)