Re: Data File
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Apr 23, 1998
- 634 views
>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]