
-----------------------------------
pokerface
Tue Nov 09, 2004 7:49 pm

tokens
-----------------------------------
i would like to know how to out put a certain amount of tokens coming from a file

example:

if my text file has 10 words in it, i want to out put 2 words at a time right after each other
*********************file*************************
one two three four five six seven eight nine ten
********************end of file*********************
*************************************************
*******************output************************
one two
three four
five six
seven eight
nine ten
*******************end of output********************

do u know what i mean? im sorry that i always post new topics but i didnt find anything on tokens from files?
ty!

-----------------------------------
myob
Tue Nov 09, 2004 8:18 pm


-----------------------------------
okay i did a program that does that, hopefully it helps

this is the code for the program

var file, counter : int
open : file, "data.txt", get
var data : flexible array 1 .. 0 of string
counter := 0
loop
    counter := counter + 1
    new data, counter
    get : file, skip
    get : file, data (counter)
    exit when eof (file)
end loop
for i : 3 .. counter + 2
    if i mod 2 = 1 then
        put data (i - 2), " " ..
    else
        put data (i - 2)
    end if
end for


this is what is in the file "data.txt"

one two three four five six seven eight nine ten


-----------------------------------
pokerface
Tue Nov 09, 2004 10:10 pm


-----------------------------------
yes your right about that but i want the user to say how many tokens they want to be on each line! my example was only a example! is there some other code that may do that?

-----------------------------------
myob
Wed Nov 10, 2004 2:26 am


-----------------------------------
i see you just not very efficient with ur codes yet. look at the following codes and tell me if they do what u want, and check out how much of a different it brings comparing to my first set of codes. sometimes generalization is all you need.
var file, counter : int
open : file, "data.txt", get
var data : flexible array 1 .. 0 of string
counter := 0
loop
    counter := counter + 1
    new data, counter
    get : file, skip
    get : file, data (counter)
    exit when eof (file)
end loop
var n : int
put "How many words do you want on a line?"
get n
for i : 1 + n .. counter + n
    if i mod n = 0 then
        put data (i - n)
    else
        put data (i - n), " " ..
    end if
end for


-----------------------------------
pokerface
Wed Nov 10, 2004 7:12 pm


-----------------------------------
i have no idea what var data : flexible array 1 .. 0 of string  is? could u explain it to me or show me another way?

-----------------------------------
wtd
Wed Nov 10, 2004 9:00 pm


-----------------------------------
i have no idea what var data : flexible array 1 .. 0 of string  is? could u explain it to me or show me another way?

This is a declaration of an array of strings which can grow later in the program, if necessary.  Declaring it with initial bounds of 1 .. 0 means that it has space for nothing, initially.

-----------------------------------
pokerface
Sat Nov 13, 2004 4:15 pm


-----------------------------------
i think this is easier!
var word : string
var newtext : int
var count : int := 0
var newword : string := ""
var list : int
open : newtext, "Newtext.t", get
assert newtext > 0
loop
    get : newtext, skip
    exit when eof (newtext)
    loop
        get : newtext, skip
        exit when eof (newtext)
        count := count + 1
        get : newtext, word
        if count not= 4 then
            put word + " " ..
        elsif count = 4 then
            put word ..
            put " "
            count := 0
            exit
        end if
    end loop
end loop
this is all i know how to do it? is there a way to get rud of the second loop without changing to much to my snytax?

-----------------------------------
pokerface
Mon Nov 15, 2004 10:50 pm


-----------------------------------
Does anyone know how to right justify the output? Every that i tried always makes it funky!!! This is what i got so far!

 var text : int
open : text, "newText.txt", get
var maxLength : int := 10
var word : string
var lineLength : int := 0
var deleting : int
loop
    get : text, skip
    exit when eof (text)
    get : text, word
    if lineLength + length (word) < maxLength then
        put word, " " ..
        lineLength := lineLength + length (word) + 1
    else
        put ""
        put word, " " ..
        lineLength := length (word)
    end if
end loop


-----------------------------------
HyperFlexed
Tue Nov 16, 2004 8:57 pm


-----------------------------------
Does anyone know how to right justify the output? Every that i tried always makes it funky!!! This is what i got so far!

 var text : int
open : text, "newText.txt", get
var maxLength : int := 10
var word : string
var lineLength : int := 0
var deleting : int
loop
    get : text, skip
    exit when eof (text)
    get : text, word
    if lineLength + length (word) < maxLength then
        put word, " " ..
        lineLength := lineLength + length (word) + 1
    else
        put ""
        put word, " " ..
        lineLength := length (word)
    end if
end loop



proc RightAlign (alignThis:string)
Text.Locate (Text.WhatRow,Text.maxcol-length(alignThis))
put alignThis
end RightAlign

