Computer Science Canada

reading from file qwerks

Author:  qwerty654321 [ Mon Feb 24, 2003 8:08 am ]
Post subject:  reading from file qwerks

okay heres the problem....
when reading from a file im reading lines e.g.


this is a line
this is another line


now if i want to read each word i just say

get : streamnum, word

now if that was looped id get 'this' 'is' 'a' 'line' 'this' 'is' 'another' 'line'

HOWEVER..

i wan to know a good way to seperate it into 2 lines similar to how i read it from the file instead of a new long sentence....ne ideas?

e.g. out put (without the '')

'this' 'is' 'a' 'line'
'this' 'is' 'another' 'line'

Author:  hey_joe42 [ Mon Feb 24, 2003 11:03 am ]
Post subject:  try this

var fn : int
var count := 0
var sentence : string
open : fn, "line.txt", get
loop
exit when eof (fn)
get : fn, sentence : *
for i : 1 .. length (sentence)
if sentence (i) = " " then
count += 1
end if
end for
var word := "" %array 1..count of string
for i : 1 .. count
if sentence (i) not= " " then
word += sentence (i)
else
put word
end if
end for
end loop
might work try it or fix it

Author:  Tony [ Mon Feb 24, 2003 1:53 pm ]
Post subject: 

the Censor problem for CCC competition asks similar question. We have a number of solutions posted there, you might be interested in reading some.


: