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

Username:   Password: 
 RegisterRegister   
 how do i store words into arrays? (from text file)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Zorg




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Jan 23, 2004 3:30 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zorg




PostPosted: Fri Jan 23, 2004 3:32 pm   Post subject: (No subject)

can you give me a simple example?
Tony




PostPosted: Fri Jan 23, 2004 3:34 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Zorg




PostPosted: Fri Jan 23, 2004 5:32 pm   Post subject: (No 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?
JHDK




PostPosted: Fri Jan 23, 2004 8:30 pm   Post subject: (No 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.
Thuged_Out_G




PostPosted: Fri Jan 23, 2004 11:50 pm   Post subject: (No 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
Zorg




PostPosted: Fri Jan 23, 2004 11:54 pm   Post subject: (No subject)

Thank you so much! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Sat Jan 24, 2004 12:07 am   Post subject: (No subject)

but put
code:
get:stream,skip

above
code:
exit when eof(stream)
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  [ 9 Posts ]
Jump to:   


Style:  
Search: