Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem about reading data Posted by anyman on 17 Dec 2004 at 7:52 AM
Well.. my situation is like that.I wrote a problem provide many questions, you can choose the number of question you wanna answer.
Once you choose the answer the hint will show in the program.ALL question, answer and hint I used 3 different txt files put them.
Here is the problem:
1.How can I know the first line and second line only in the no.1 question load 3 and 4 line only in the no.2 question.
2.How can I check the answer to compare with the answer in the name of "answer" file.
3.How to prevent the users play the same question again.
Report
Re: Problem about reading data Posted by zibadian on 17 Dec 2004 at 8:48 AM
: Well.. my situation is like that.I wrote a problem provide many questions, you can choose the number of question you wanna answer.
: Once you choose the answer the hint will show in the program.ALL question, answer and hint I used 3 different txt files put them.
: Here is the problem:
: 1.How can I know the first line and second line only in the no.1 question load 3 and 4 line only in the no.2 question.
: 2.How can I check the answer to compare with the answer in the name of "answer" file.
: 3.How to prevent the users play the same question again.
:
The access to textfiles is quite limited; you cannot move up and down the file. ou can however move to the start of the file (Reset() procedure). Here is a sample code to read 2 lines from a textfile based on an integer called Index:
  Reset(f);
  for i := 1 to Index do
  begin
    Readln(f, FirstLine);
    Readln(f, SecondLine);
  end;

In your case Index is the question number.

2. With a slight modification the code above can also be used here. Just remove the reading of the second line and change the file variable of course.

3. Keep a list of the questions the user already has answered. The best method is to use an array of booleans. The only problem is that you cannot have more than about 64000 different questions this way. You can multiply that number by 8, if you create a code to use bits instead of booleans.
Report
Re: Problem about reading data Posted by anyman on 17 Dec 2004 at 8:48 PM
: The access to textfiles is quite limited; you cannot move up and down the file. ou can however move to the start of the file (Reset() procedure). Here is a sample code to read 2 lines from a textfile based on an integer called Index:
:
:   Reset(f);
:   for i := 1 to Index do
:   begin
:     Readln(f, FirstLine);
:     Readln(f, SecondLine);
:   end;
: 

: In your case Index is the question number.
:
: 2. With a slight modification the code above can also be used here. Just remove the reading of the second line and change the file variable of course.

:
I don't quite understand what is the function of reset

Report
Re: Problem about reading data Posted by zibadian on 17 Dec 2004 at 11:25 PM
: : The access to textfiles is quite limited; you cannot move up and down the file. ou can however move to the start of the file (Reset() procedure). Here is a sample code to read 2 lines from a textfile based on an integer called Index:
: :
: :   Reset(f);
: :   for i := 1 to Index do
: :   begin
: :     Readln(f, FirstLine);
: :     Readln(f, SecondLine);
: :   end;
: : 

: : In your case Index is the question number.
: :
: : 2. With a slight modification the code above can also be used here. Just remove the reading of the second line and change the file variable of course.
:
: :
: I don't quite understand what is the function of reset
:
:
That places the "file-cursor" back to the beginning of the file. It is well covered in the help files.
Report
Re: Problem about reading data Posted by anyman on 18 Dec 2004 at 2:00 AM
: : : The access to textfiles is quite limited; you cannot move up and down the file. ou can however move to the start of the file (Reset() procedure). Here is a sample code to read 2 lines from a textfile based on an integer called Index:
: : :
: : :   Reset(f);
: : :   for i := 1 to Index do
: : :   begin
: : :     Readln(f, FirstLine);
: : :     Readln(f, SecondLine);
: : :   end;
: : : 

: : : In your case Index is the question number.
: : :
: : : 2. With a slight modification the code above can also be used here. Just remove the reading of the second line and change the file variable of course.
: :
: : :
: : I don't quite understand what is the function of reset
: :
: :
: That places the "file-cursor" back to the beginning of the file. It is well covered in the help files.
:
could u give me a sample



 

Recent Jobs