Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem about reading data

anymananyman Posts: 19Member
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.

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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:
    [code]
    Reset(f);
    for i := 1 to Index do
    begin
    Readln(f, FirstLine);
    Readln(f, SecondLine);
    end;
    [/code]
    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.
  • anymananyman Posts: 19Member
    : 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:
    : [code]
    : Reset(f);
    : for i := 1 to Index do
    : begin
    : Readln(f, FirstLine);
    : Readln(f, SecondLine);
    : end;
    : [/code]
    : 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

  • zibadianzibadian Posts: 6,349Member
    : : 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:
    : : [code]
    : : Reset(f);
    : : for i := 1 to Index do
    : : begin
    : : Readln(f, FirstLine);
    : : Readln(f, SecondLine);
    : : end;
    : : [/code]
    : : 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.
  • anymananyman Posts: 19Member
    : : : 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:
    : : : [code]
    : : : Reset(f);
    : : : for i := 1 to Index do
    : : : begin
    : : : Readln(f, FirstLine);
    : : : Readln(f, SecondLine);
    : : : end;
    : : : [/code]
    : : : 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
Sign In or Register to comment.