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

Username:   Password: 
 RegisterRegister   
 Reading a data file line with a space in it
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Bman54




PostPosted: Thu Nov 12, 2009 11:15 am   Post subject: Reading a data file line with a space in it

What is it you are trying to achieve?
I'm trying to make a quiz game and some my answers and questions are in a data file, but if I try to read a line that has a space in it, it only read the first word and then reads the next word as a separate line.


What is the problem you are having?
How can I make it so it read the whole line and stores in one variable instead of separate ones?


Describe what you have tried to solve this problem
I have no idea how to solve this.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is what I've got to read it normally.

Turing:


var score: int
var question, answer: string %Hold the lines to the data file.
var inp : int %Turing requires this integer variable
score := 0
open : inp, "provinces.txt", get %open the file provinces.txt for reading
loop
     exit when eof(inp) %Exit when the end-of-file is reached
     get: inp, question %Read the [ctr]th line from the data file, and store it in the string variable question
     get: inp, answer
     put "The capital of ", question ," is ", answer ,"."
end loop>



And this is my data file:
Ontario
Toronto
Quebec
Quebec City
Manitoba
Winnipeg
Prince Edward Island
Charlottetown
New Brunswick
Fredericton
British Columbia
Victoria
Alberta
Edmonton
Saskatchewan
Regina
Nunavut
Iqaluit
Newfoundland and Labrador
St. John's
Nova Scotia
Halifax
Yukon
Whitehorse
Northwest Territories
Yellowknife

(I'm doing a Province/Capital quiz game)

Please specify what version of Turing you are using
This is on Turing 4.0.3

Also, the code I have is not really my quiz game yet. I'm starting off like this so I understand how to read a data file properly when I really get to making the quiz.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Nov 12, 2009 12:06 pm   Post subject: Re: Reading a data file line with a space in it

Read the documentation on -- get

In particular
code:

get: inp, question:*
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Kharybdis




PostPosted: Thu Nov 12, 2009 3:01 pm   Post subject: RE:Reading a data file line with a space in it

ah tony, you're too fast!
Tony




PostPosted: Thu Nov 12, 2009 3:12 pm   Post subject: RE:Reading a data file line with a space in it

I'm sorry Sad
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Bman54




PostPosted: Fri Nov 13, 2009 11:07 am   Post subject: RE:Reading a data file line with a space in it

Thanks for the help!
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  [ 5 Posts ]
Jump to:   


Style:  
Search: