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

This is a discussion on how do I read the last line of a text file? within the C Programming forums, part of the General Programming Boards category; I have a huge file but I only want to read the last line and store the different fields in ...

  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,648
    while(fgets(buff, 200, fp));

    Just uses the same buffer for each call....
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  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, 01: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, 01: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

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