1. Data File
- Posted by David P Mosley <david08 at JUNO.COM> Apr 23, 1998
- 650 views
Hi I have been trying to do a data file in euphoria for a quiz game that I am doing and I am a little stuck on this one.Ok here it is I have a file(data) like this How old are you? 37 What time of day is it. 2:00pm 1question 2 answer when I read in the file I get 1 long seq like this H,o,w, ,o,l,d, ,etc. what I need is this ({{How old are you?},{What time of day is it.}}) ({{37},{2:00pm}}) what I want to do is read it into a array then I can get the questions out when I need to and the answers also. Hope this makes sence In Christ David Mosley david08 at juno.com _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]
2. Re: Data File
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Apr 23, 1998
- 635 views
- Last edited Apr 24, 1998
>I have been trying to do a data file in euphoria for a quiz game that >I am doing and I am a little stuck on this one.Ok here it is I have a >file(data) like this >How old are you? >37 >What time of day is it. >2:00pm >1question 2 answer >when I read in the file I get 1 long seq like this >H,o,w, ,o,l,d, ,etc. >what I need is this >({{How old are you?},{What time of day is it.}}) >({{37},{2:00pm}}) >what I want to do is read it into a array then I can get the questions >out when I need to and the answers also. >Hope this makes sence I think so. You want the data file to look like this: {"How old are you?", "What time of day is it?"} {"37", "2:00pm"} Correct? If so, the code should look something like this. --==[Untested code!]==-- include get.e sequence question, answer integer fn -- Open the file (assume success in this code snippit. NEVER assume -- this in the actual code fn = open("data.dat", "r") -- Get the questions question = get(fn) if question[1] = GET_SUCCESS then question = question[2] end if -- Get the answers, if present. answer = get(fn) if answer[1] = GET_SUCCESS then answer = answer[2] puts(1, "\nThe questions have been answered.\n") else answer = repeat("", length(question)) puts(1, "\nThe questions have not been answered.\n") end if close(fn) -- Do code for getting the answers and questions and such. for i = 1 to length(question) puts(1, question[i] & " ") answer[i] = gets(0) answer[i] = answer[i][1..length(answer[i])-1] -- Strip off \n puts(1, "\n\n") end for -- Place data into file (Assumes success in opening file) -- This method won't be easy to read, though. open("data.dat", "w") print(fn, question) print(fn, answer) -- end untested code If you need to be able to read the data file, then I can give a way to do that also. If this isn't close enough to what you need, tell me what is off so I can fix it. :) _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]
3. Re: Data File
- Posted by Irv Mullins <irv at ELLIJAY.COM> Apr 23, 1998
- 627 views
- Last edited Apr 24, 1998
At 07:56 PM 4/23/98 -0600, you wrote: >---------------------- Information from the mail header ----------------------- >Sender: Euphoria Programming for MS-DOS <EUPHORIA at >MIAMIU.ACS.MUOHIO.EDU> >Poster: David P Mosley <david08 at JUNO.COM> >Subject: Data File >------------------------------------------------------------------------------- > >Hi >I have been trying to do a data file in euphoria for a quiz game that I >am doing and I am a little stuck on this one.Ok here it is I have a >file(data) like this >How old are you? >37 >What time of day is it. >2:00pm >1question 2 answer >when I read in the file I get 1 long seq like this >H,o,w, ,o,l,d, ,etc. >what I need is this >({{How old are you?},{What time of day is it.}}) >({{37},{2:00pm}}) >what I want to do is read it into a array then I can get the questions >out when I need to and the answers also. >Hope this makes sence You have a file with alternating questions and answers? Here's how to read them in from a text file: object input, question, answer question = {} answer = {} atom fn fn = open("QUESTION.DAT","r") while 1 do -- load the data input = gets(fn) -- read the question if atom(input) then exit -- end of file else question = append(question,input) end if input = gets(fn) -- read the answer if atom(input) then exit -- eof else answer = append(answer,input) end if end while close(fn) -- now you can print question[n] and matching answer[n] -- or compare them, etc. Spam Haiku:------------------- Silent, former pig One communal awareness Myriad pink bricks -------------------------------------