Computer Science Canada

how do i store words into arrays? (from text file)

Author:  Zorg [ Fri Jan 23, 2004 3:28 pm ]
Post subject:  how do i store words into arrays? (from text file)

How do i store each word into an array from a text file?

Author:  Tony [ Fri Jan 23, 2004 3:30 pm ]
Post subject: 

you read from the textfile one word at a time, keep a running counter and save each word into an array with counter as the index

Author:  Zorg [ Fri Jan 23, 2004 3:32 pm ]
Post subject: 

can you give me a simple example?

Author:  Tony [ Fri Jan 23, 2004 3:34 pm ]
Post subject: 

code:

my_Array(counter) := tempWord

Confused

we have tutorials on reading from file and using arrays in [turing tutorials], you'll find them helpful Smile

Author:  Zorg [ Fri Jan 23, 2004 5:32 pm ]
Post subject: 

tony wrote:
you read from the textfile one word at a time, keep a running counter and save each word into an array with counter as the index


How exactly do I take one word at a time?

Author:  JHDK [ Fri Jan 23, 2004 8:30 pm ]
Post subject: 

lol. i had to do this for database.
just declare some variables as an array and load your file, then save your text to the variables in the array.

Author:  Thuged_Out_G [ Fri Jan 23, 2004 11:50 pm ]
Post subject: 

code:

var stream:int
var line:string
var count:=0
var words:array 1..1000 of string
open:stream,"filename.txt",get
assert stream >0

loop
count +=1
if count > 1000 then
exit
else
get:stream,skip
exit when eof(stream)
get:stream,line
words(count):=line
end if
end loop

for i:1..1000
put words(i)
if words(i)="" then
if words(i+1)="" then
exit
end if
end if
end for

Author:  Zorg [ Fri Jan 23, 2004 11:54 pm ]
Post subject: 

Thank you so much! Very Happy

Author:  McKenzie [ Sat Jan 24, 2004 12:07 am ]
Post subject: 

but put
code:
get:stream,skip

above
code:
exit when eof(stream)


: