Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 reading from file qwerks
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
qwerty654321




PostPosted: 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'
Sponsor
Sponsor
Sponsor
sponsor
hey_joe42




PostPosted: 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
Tony




PostPosted: Mon Feb 24, 2003 1:53 pm   Post subject: (No 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: