help with parallel arrays!

This is a discussion on help with parallel arrays! within the C Programming forums, part of the General Programming Boards category; i have a file attach below how can i read data from the file in to 6 following arrays int ...

  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, 39 views)
    Last edited by khoavo123; 01-30-2012 at 01: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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03:07 PM
  4. Parallel Arrays with Multiple Arrays
    By Billye Scott in forum C++ Programming
    Replies: 0
    Last Post: 03-02-2002, 10:14 PM
  5. parallel arrays
    By KeeNCPP in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2001, 09:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21