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

Username:   Password: 
 RegisterRegister   
 Reading .txt files
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Chris




PostPosted: Thu Feb 16, 2006 8:28 pm   Post subject: Reading .txt files

Im writing a programing challenge in a couple weeks that requires file input. Here is what I have gathered so far:

code:
var stremin :int
var nums:string
open: stremin, "payroll.txt", get
loop
      exit when eof (stremin)
      get: stremin, nums
end loop
close: stremin
put nums


This works, but I need multiple words to be stored. If you could, I would like to know how to store each word individually (in an array) in one long string. Thanks in advance, and I know you guys wont respond with "read the help" because your all so helpful and nice Very Happy

Thanks again for any help.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Feb 16, 2006 8:35 pm   Post subject: Re: Reading .txt files

Chris wrote:
Thanks in advance, and I know you guys wont respond with "read the help" because your all so helpful and nice Very Happy

Of course not... Read the Turing Walkthrough. Wink

Just kidding.

You'll need to learn to use a Flexible Array. With each word you get, add a new element to your flexible array, assigned that new element to the value gotten. However, we can optimize this. Rather than getting each word into a temporary variable and assigned that to the new, upper element of the flex. array, we can get the word directly into the upper element of the flex array.

For example,
code:

var stream_in : int
var words : flexible array 1 .. 0 of string
open : "payroll.txt", stream_in, get
loop
    exit when eof(stream_in)
    new words, upper (words) + 1
    get : stream_in, words (upper (word))
end loop
close : stream_in
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  [ 2 Posts ]
Jump to:   


Style:  
Search: