writing a program called tail like the one in unix

This is a discussion on writing a program called tail like the one in unix within the C Programming forums, part of the General Programming Boards category; Hi can someone help me. I have to write a program called tail that will read lines from a file ...

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

    Cool writing a program called tail like the one in unix

    Hi can someone help me. I have to write a program called tail that will read lines from a file until it comes to the EOF, then the program should print out the last n lines of input. Its similar to the tail in unix. Thanks


  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main ( void )
    {
       char buf[1024]={0};
       sprintf( buf, "tail %s %s", argv[1], argv[2] );
       system( buf );
       return 0;
    }
    It doens't get much simpler than that. Seriously, post your code. Read the god damn homework post and the FAQ.

    Quzah.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    Have you figured out how to implement the opposite command 'head', to print out the first 10 lines of a file?

    It doesn't take much to get from one to the other.
    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. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Replies: 1
    Last Post: 12-10-2005, 10:25 AM
  3. writing a grep program
    By cnovice in forum C Programming
    Replies: 8
    Last Post: 11-22-2005, 07:05 AM
  4. Writing a program, need some help.
    By ChrisH in forum C Programming
    Replies: 4
    Last Post: 12-01-2004, 02:54 PM
  5. Remotely accessing an NT PC from a Unix C++ program
    By bhorrobi in forum C++ Programming
    Replies: 0
    Last Post: 10-01-2001, 09:42 AM

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