Loading multiple files in Turing
Author |
Message |
mains50
|
Posted: Wed Jun 02, 2010 6:38 pm Post subject: Loading multiple files in Turing |
|
|
What is it you are trying to achieve?
Loading a file in turing. The file contains question to my millionair game.
What is the problem you are having?
I dont know how to upload choices A, B,C,D from the file with the question.
Description: |
this file has the questions + the choices in it |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Question.txt |
Filesize: |
452 Bytes |
Downloaded: |
83 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Wed Jun 02, 2010 9:30 pm Post subject: RE:Loading multiple files in Turing |
|
|
What do you have so far? If your clueless then here's a little example that'll read the first line in a file and write it to the screen.
Turing: |
var fileName : string := "demo.txt"
var fileNo : int %File Number placeholder variable
var line : string
open : fileNo, fileName, get
get : fileNo, line :*
put line
close : fileNo
|
You can find a good explanation of File input and output here: http://compsci.ca/v3/viewtopic.php?t=12972
|
|
|
|
|
![](images/spacer.gif) |
mains50
|
Posted: Wed Jun 02, 2010 9:41 pm Post subject: Re: RE:Loading multiple files in Turing |
|
|
Zren @ Wed Jun 02, 2010 9:30 pm wrote: What do you have so far? If your clueless then here's a little example that'll read the first line in a file and write it to the screen.
Turing: |
var fileName : string := "demo.txt"
var fileNo : int %File Number placeholder variable
var line : string
open : fileNo, fileName, get
get : fileNo, line :*
put line
close : fileNo
|
You can find a good explanation of File input and output here: http://compsci.ca/v3/viewtopic.php?t=12972
yes i have the code to get the questions, but i dont know how to get the choices of the question.
|
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Wed Jun 02, 2010 10:07 pm Post subject: RE:Loading multiple files in Turing |
|
|
What's your code so far?
|
|
|
|
|
![](images/spacer.gif) |
mains50
|
Posted: Thu Jun 03, 2010 10:23 am Post subject: Re: RE:Loading multiple files in Turing |
|
|
Zren @ Wed Jun 02, 2010 10:07 pm wrote: What's your code so far?
this is what i got so far
%Variabbles for the file
var millFile : int
var noOfPhrase : int
%opening the file
open : millFile, "word.txt", get
get : millFile, noOfPhrase
% read the phrase into the list
var phraseList : array 1 .. noOfPhrase of string
for phraseNo : 1 .. noOfPhrase
get : millFile, phraseList (phraseNo) : *
for A : 1.. noOfPhrase
get: millFile, A (PhraseNo): *
end for
% close file
close : millFile
|
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Thu Jun 03, 2010 11:11 am Post subject: RE:Loading multiple files in Turing |
|
|
Please surround your code with this to keep whitespace and add syntax highlighting: code: | [syntax="turing"] ... [/syntax] |
First off, our text file should get rid of the empty lines. It's easier for us to read yes, but it's more confusing to program (you have to get: empty lines to progress through the file).
Okay, clear up what's inside the for loop and start from scratch here.
Each question has 1 line for the question. Next 4 lines for the answers. However, we really only need to process 1 question (and 4 answers) at a time, so we don't really need to store all the phrases at once (unless you plan on randomizing things and that's complicated, better to get the basics first).
By the way, were you considering adding the correct answer into the file as well?
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Thu Jun 03, 2010 1:26 pm Post subject: RE:Loading multiple files in Turing |
|
|
I dont think the problem is loading, I think he needs to learn arrays
|
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Thu Jun 03, 2010 1:46 pm Post subject: Re: Loading multiple files in Turing |
|
|
They're already correctly using one array.
Here's something that stands out as odd though:
Turing: |
for A : 1.. noOfPhrase
get: millFile, A (PhraseNo): *
end for
|
Exactly what are you trying to do with that? As far as I can tell, you're trying to read from the file and put it into a non-existent subscript of your for loop's counter...
A is, first of all, not an array, and second of all not a String. It is an integer that is being used to count your for loop. It is also local, meaning that it can't be accessed at all outside of that for loop.
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Thu Jun 03, 2010 2:56 pm Post subject: Re: Loading multiple files in Turing |
|
|
Thats why I said he need to learn that ;p I don't think he knows what hes doing since he basically just copied the code lol and I'm saying this because he has a mix of proper camel-casing and well variable names that don't! /*he is having issues with what he actually tried to make*/ .Hes forgoten to end a for loop, and 'A' obviously cannot have sub scripts.
What he is trying to do :
Turing: | %Sets a type with the values for one question
type questionData :
record
question : string
options : array 0 .. 3 of string
answer : int
end record
%File strean identifier and length of upper bound integers
var streamID, numOfQuestions : int
%Opens word.txt through the files streamID variable
open : streamID, "word.txt", get
%Gets the upper bound for the number of questions
get : streamID, numOfQuestions
%Decaliars an array of questions type specified above
var questions : array 0 .. numOfQuestions - 1 of questionData
%For the lower bound of questions to the upper bound of questions
for i : lower (questions ) .. upper (questions )
%Gets the question and saves the line
get : streamID, questions (i ).question : *
%For the lower bound of the options under the bound of questions to the upper bound
%of options under the bound of questions if that is explained right lol.
for j : lower (questions (i ).options ) .. upper (questions (i ).options )
%Gets the 4 choices needed t answer the question and saves it.
get : streamID, questions (i ).options (j ) : *
%End of for loop
end for
%End of for loop
end for
%Close file
close : streamID |
Also dont take it personal, if this is your first semester programing, its great you tried actually using arrays and theres nothing wrong if you can't get your head completly around 2D arrays, but dont take other peoples code and call it your own .
|
|
|
|
|
![](images/spacer.gif) |
mains50
|
Posted: Thu Jun 03, 2010 5:29 pm Post subject: Re: Loading multiple files in Turing |
|
|
copthesaint @ Thu Jun 03, 2010 2:56 pm wrote: Thats why I said he need to learn that ;p I don't think he knows what hes doing since he basically just copied the code lol and I'm saying this because he has a mix of proper camel-casing and well variable names that don't! /*he is having issues with what he actually tried to make*/ ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) .Hes forgoten to end a for loop, and 'A' obviously cannot have sub scripts.
What he is trying to do :
Turing: | %Sets a type with the values for one question
type questionData :
record
question : string
options : array 0 .. 3 of string
answer : int
end record
%File strean identifier and length of upper bound integers
var streamID, numOfQuestions : int
%Opens word.txt through the files streamID variable
open : streamID, "word.txt", get
%Gets the upper bound for the number of questions
get : streamID, numOfQuestions
%Decaliars an array of questions type specified above
var questions : array 0 .. numOfQuestions - 1 of questionData
%For the lower bound of questions to the upper bound of questions
for i : lower (questions ) .. upper (questions )
%Gets the question and saves the line
get : streamID, questions (i ).question : *
%For the lower bound of the options under the bound of questions to the upper bound
%of options under the bound of questions if that is explained right lol.
for j : lower (questions (i ).options ) .. upper (questions (i ).options )
%Gets the 4 choices needed t answer the question and saves it.
get : streamID, questions (i ).options (j ) : *
%End of for loop
end for
%End of for loop
end for
%Close file
close : streamID |
Also dont take it personal, if this is your first semester programing, its great you tried actually using arrays and theres nothing wrong if you can't get your head completly around 2D arrays, but dont take other peoples code and call it your own .
i did not take anyone code it was my own, btw i got my problem solved but thanks for your help
|
|
|
|
|
![](images/spacer.gif) |
mains50
|
Posted: Thu Jun 03, 2010 5:30 pm Post subject: Re: Loading multiple files in Turing |
|
|
TheGuardian001 @ Thu Jun 03, 2010 1:46 pm wrote: They're already correctly using one array.
Here's something that stands out as odd though:
Turing: |
for A : 1.. noOfPhrase
get: millFile, A (PhraseNo): *
end for
|
Exactly what are you trying to do with that? As far as I can tell, you're trying to read from the file and put it into a non-existent subscript of your for loop's counter...
A is, first of all, not an array, and second of all not a String. It is an integer that is being used to count your for loop. It is also local, meaning that it can't be accessed at all outside of that for loop.
oh that part i just added it in, i forgot to remove it.. but i got my problem solved thanks for your help
|
|
|
|
|
![](images/spacer.gif) |
|
|