
-----------------------------------
r0ssar00
Tue Sep 20, 2005 1:49 pm

help with strings and removing stuff
-----------------------------------
i built a lib for finding the biggest word in a string with three words or less

when i use the lib from within it, like a proc, it works fine, but when i import it into a test prog that i wrote up, it returns the shortest word

 it only manifests itself when the data passed to it is in the form of a variable.  when the data passed to it is just a string not in a var,  as in on the same line, in brackets, it works fine.  

could i get some help with this?

its just a general lib that can b used for anything, its not very specific except for what it does. 

the main object is returnBiggest and it's a function


heres the prog

unit %comment out to test in lib file, otherwise, uncomment to allow importing
module processName
    export returnBiggest
    var biggest : string
    fcn returnBiggest (name : string) : string
        var firstName := name
        for i : 1 .. length (name)
            if name (i) = " " then
                firstName := name (1 .. i - 1)
                exit
            end if
        end for


        var middleName := ""
        var firstSpace := 0
        if firstName not= name then
            for i : 1 .. length (name)
                if name (i) = " " and firstSpace ~= 0 then
                    middleName := name (firstSpace + 1 .. i - 1)
                end if
                if name (i) = " " then
                    firstSpace := i
                end if
            end for
        end if

        var lastName := ""
        if firstName + " " + middleName not= name then
            for i : 1 .. length (name)
                if name (i) = " " then
                    lastName := name (i + 1 .. *)
                end if
            end for
        end if
        var lengths : array 1 .. 3 of int
        lengths (1) := length (firstName)
        lengths (2) := length (middleName)
        lengths (3) := length (lastName)
        if lengths (1) > lengths (2) and lengths (1) > lengths (3) then
            biggest := firstName
        elsif lengths (2) > lengths (1) and lengths (2) > lengths (3) then
            biggest := middleName
        elsif lengths (3) > lengths (1) and lengths (3) > lengths (2) then
            biggest := lastName
        end if
        result biggest
    end returnBiggest
end processName


and my test proggy, asks for three words or less, then prints out the result of variable returned


import processName in "./determine.tu"
var words : string
var returned : string
put "enter three words max: " ..
get words
returned := processName.returnBiggest (words)
put returned, " is the biggest word"


i really need this 2 work, the problem is probly somethin stupid, but i cant find it, plz help

-----------------------------------
beard0
Tue Sep 20, 2005 4:03 pm

Re: help with strings and removing stuff
-----------------------------------
you're really gonna kick youself:
get words

See it?  No?  :* might help get multiple words ;)

-----------------------------------
r0ssar00
Wed Sep 21, 2005 7:07 am


-----------------------------------
i kicked myslef a million times, i was right, it was somethin stupid, and it works completly now, thanks a lot.  sometimes its the stupid things u miss when looking at the big picture on how it works

-----------------------------------
wtd
Wed Sep 21, 2005 11:48 am


-----------------------------------
A "good practices" note:

returned := processName.returnBiggest (words)
put returned, " is the biggest word"

What does "returned" mean?  Sure, it's the value returned form the returnBiggest function, but there are lots of functions.

A more meaningful name would be:


biggestInputWord := processName.returnBiggest (words)
put biggestInputWord, " is the biggest word"

-----------------------------------
r0ssar00
Wed Sep 21, 2005 1:56 pm


-----------------------------------
i had only made a test program for example, conventions can go to hell in it for all i care, in my other program that uses it, i have meaningful var names. sorry, i should have done it, but it was a quicky prog.

-----------------------------------
wtd
Wed Sep 21, 2005 2:15 pm


-----------------------------------
I understand, but you should get into the habit.  Otherwise bad habits creep into all of your code.
