Thread: help with parallel arrays!

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    48

    help with parallel arrays!

    i have a file attach below how can i read data from the file in to 6 following arrays
    int ID[],
    int maxHR[],
    int age[],
    float aveCommuteHR[],
    float maxCommuteHR[],
    float excerciseHr[]);

    the first line of the data contain the id, maxHr and age, the nxt 5 lines contain the last three arrays, and the sixth line repeat the first line and next 5 lines after the sixth line also repeat and it keep repeat like that until EOF

    i was suppose to use for loop nested inside a while(!EOF) loop and was not suppose to use struct or anything else beside basic looping stuff
    Attached Files Attached Files
    • File Type: txt HR.txt (916 Bytes, 165 views)
    Last edited by khoavo123; 01-30-2012 at 02:38 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why don't you just include your code in [code] tags, and then actually ask whatever question it is you have?
    Read first:http://cboard.cprogramming.com/c-pro...e-posting.html
    Read next:http://cboard.cprogramming.com/c-pro...ead-first.html


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > i was suppose to use for loop nested inside a while(!EOF) loop and was not suppose to use struct or anything else beside basic looping stuff
    Well in your other thread -> help with parallel array

    while(!EOF)
    Just isn't going to do what you want it to do.
    EOF is a numeric constant (usually -1, also equivalent to 'true'). So saying !EOF is like saying 'false', so your loop does nothing.

    Perhaps you should have
    Code:
    while ( i< NUM_PATIENT && fscanf(spData,"%d %d %d", &ID[i], &maxHR[i], &age[i]) == 3 ) {
        fprintf(spData,"%d %d %d", ID[i], maxHR[i], age[i]);
        i++;
    }
    Or (satisfying the assignment, but not very safe)
    Code:
    while ( i< NUM_PATIENT && fscanf(spData,"%d %d %d", &ID[i], &maxHR[i], &age[i]) != EOF ) {
        fprintf(spData,"%d %d %d", ID[i], maxHR[i], age[i]);
        i++;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modifying parallel arrays to arrays of structures
    By xkohtax in forum C Programming
    Replies: 7
    Last Post: 07-28-2011, 12:07 AM
  2. Parallel arrays
    By beginner1 in forum C Programming
    Replies: 2
    Last Post: 05-19-2009, 08:53 AM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. Parallel Arrays with Multiple Arrays
    By Billye Scott in forum C++ Programming
    Replies: 0
    Last Post: 03-02-2002, 11:14 PM
  5. parallel arrays
    By KeeNCPP in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2001, 09:56 PM