Thread: still a problem with txt files

  1. #1
    Registered User Makaila's Avatar
    Join Date
    Oct 2009
    Posts
    10

    still a problem with txt files

    what code would you use to put this:

    1.question
    answer1
    answer2
    answer3
    answer4
    2.question
    answer1
    answer2
    answer3
    answer4 and so on for 15 questions

    into this:
    Code:
    struct quiz
    {
       char q[81], a[4][81];
    } question[15];
    I'm runnin' out of idas and nothing works!!! It doesn't read data from a file to a structure.

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote Originally Posted by Makaila View Post
    what code would you use...
    Code:
    for (i = 0; i < number_of_questions; i++) {
    
        /* use getline() to read question[i].q from the file */ 
    
        for (j = 0; j < number_of_answers_for_each_question; j++) {
    
            /* use getline() to read question[i].a[j] from the file */
    
        }
    }

    D.
    Last edited by Dave Evans; 01-17-2010 at 06:14 PM.

  3. #3
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    HINT: Your first problem involves while( !fin.eof() )


    J.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  4. #4
    Registered User Makaila's Avatar
    Join Date
    Oct 2009
    Posts
    10
    Thank you so much, Jeffcobb! while( !fin.eof() ) was the problem... I'm done now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. txt file from ofstream. Increment the files name?
    By Swerve in forum C++ Programming
    Replies: 5
    Last Post: 10-14-2008, 12:25 PM
  2. Reading a txt file into a struct problem
    By Swerve in forum C++ Programming
    Replies: 10
    Last Post: 03-19-2008, 12:56 AM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  4. C++ and txt files
    By 182 in forum C++ Programming
    Replies: 6
    Last Post: 10-11-2005, 03:15 PM
  5. Problem with cgi script - can't rename files
    By bjdea1 in forum C Programming
    Replies: 2
    Last Post: 12-12-2001, 04:09 PM