Thread: how do I read the last line of a text file?

  1. #1
    Unregistered
    Guest

    how do I read the last line of a text file?

    I have a huge file but I only want to read the last line and store the different fields in that last line in some variables. Is there any efficient way to do this? Thanks.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    while(fgets(buff, 200, fp));

    Just uses the same buffer for each call....
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Unregistered
    Guest
    Thanks. That worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help is needed to read text from a file
    By yuzhangoscar in forum C Programming
    Replies: 12
    Last Post: 09-12-2008, 12:10 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. reading a text file printing line number
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-16-2005, 10:31 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM