help!

This is a discussion on help! within the C++ Programming forums, part of the General Programming Boards category; I need write a C program to get all the number from a file such as the following: 0.41 184.67 ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    101

    help!

    I need write a C program to get all the number from a file such as the following:
    0.41 184.67 63.34 265.00 191.69 157.24 114.78 293.58 269.62 244.64 57.05 281.45
    232.81 168.27 99.61 4.91 29.95 119.42 48.27 54.36 323.91 146.04 39.02 1.53
    2.92 123.82 174.21 187.16 197.18 198.95 54.47 217.26 147.71 115.38 18.69 199.12
    256.67 262.99 170.35 98.94 287.03 238.11 313.22 303.33 176.73 46.64 151.41 77.11
    282.53 68.68 255.47 276.44 326.62 327.57 200.37 128.59 87.23 97.41 275.29 7.78


    so that i can do some calculation.

    i tried to use 'fgets' to get all the value
    but I can't get all the values from the file.
    What can I do?? Thx!

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Hmm

    Show us how far you have come in your program. I don't think anyone on this forum wants to write the entire program for you...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    With streams you use a loop until you find end of file:

    ifstream fin("yourFileName.ext")
    double num;

    while(!fin.eof())
    {
    fin >> num;
    }

    the coditional of the while loop could use another mechanism to detect end of file, eof() is just one way. I forget how to detect end of file using C.

Popular pages Recent additions subscribe to a feed

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