Results 1 to 6 of 6

Thread: Bug in function [Resolved]

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Resolved Bug in function [Resolved]

    Hello all, i have a function that calcs what's the most repeated value in a string, that string has multiple values including separator chars, the problem is that the function doesn't work for values bigger then 9.
    The function "see's" 9 as one char and the value 10 is seen as 2 chars.

    PHP Code:

        
    function mode_of_values($mystring){
            
    $bigger=-1;
            
    $data $mystring;
            
    $result count_chars($data0);
            for (
    $i=0$i count($result); $i++)
            if ((
    chr($i)!=",") and (chr($i)!=";")){
               if (
    $result[$i] != 0)
                if(
    $bigger<$result[$i]){
                    
    $bigger=$result[$i];
                    
    $character=chr($i);
                }
               }
            }
            return 
    $bigger.",".$character;
        }

    mode_of_values("1,3,4;2,3,4;2,5,6;2,6,8");//this works just fine but not when i call like:
    mode_of_values("10,11,12;10,13,14;11,12,13"); 
    Any idea how to fix this?

    Thanks
    Last edited by TDQWERTY; May 28th, 2005 at 03:45 PM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  2. #2
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Bug in function

    1,3,4;2,3,4;2,5,6;2,6,8

    I don't think that's a string. String literal is like "1,3,4;2,3,4;2,5,6;2,6,8" quoted with double quotes or '1,3,4;2,3,4;2,5,6;2,6,8' with single quotes. Your function seems to have arguments

    function some_function(arg0,arg1,arg2,arg3...) which signature is undefined.

  3. #3
    Lively Member Bolerophone's Avatar
    Join Date
    Dec 2003
    Location
    Himalayas
    Posts
    123

    Re: Bug in function

    dude,

    you have used the function in a wrong way see the parameter for count-chars is a string it does not matter whether it is 11 or 111.

    you need to write your own function that will do so.

    -amresh-
    Jobs: "Do u want to sell colored sugar water or change the world?"

    Get Firefox Now!!!
    Mendhak leaving town.

  4. #4

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Bug in function

    Quote Originally Posted by nebulom
    1,3,4;2,3,4;2,5,6;2,6,8

    I don't think that's a string. String literal is like "1,3,4;2,3,4;2,5,6;2,6,8" quoted with double quotes or '1,3,4;2,3,4;2,5,6;2,6,8' with single quotes. Your function seems to have arguments

    function some_function(arg0,arg1,arg2,arg3...) which signature is undefined.
    Yes, i missed something there, i should have said:

    mode_of_values("1,3,4;2,3,4;2,5,6;2,6,8");//this works just fine but not when i call like:
    mode_of_values("10,11,12;10,13,14;11,12,13");

    I tryed already to fix that function but never got it to work
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  5. #5

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Re: Bug in function

    Solved!
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

  6. #6
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Bug in function

    Quote Originally Posted by TDQWERTY
    Solved!
    Mind posting how?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width