Thread: Counting Number of Lines of file

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    17

    Counting Number of Lines of file

    Hi friends:

    My program logs data into a .data file continuosly. I have a .cgi program that reads the lines in the file and shows it in a browser.

    How can i make my program count the number of lines and when it reaches 10 lines then delete it? So i do't show a very large web page

    Thanks
    Daniel
    A Man can be whatever he wants to
    be

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How can i make my program count the number of lines and when it reaches 10 lines then delete it?
    Basically the way to count how many lines are in a file you read the file line by line:
    Code:
    int countLines(FILE *in)
    {
      char buff[LINELEN];
      int n = 0;
    
      rewind(in);
      while (fgets(buff, sizeof buff, in) != NULL)
        n++;
    
      return n;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM