From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Venkatesh Joshi" Subject: how to implement tail -n Date: Mon, 24 Jan 2005 11:19:10 +0530 Message-ID: <009a01c501d8$6d504cf0$dc846840@apac.cisco.com> References: <1106461572.1122.1.camel@KrishnaMohan> <20050123184550.B330@Imrashi.net.bd> <1106487378.1122.14.camel@KrishnaMohan> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: Sender: linux-c-programming-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii" To: LinuxC Hi, I would like to know how to implement "tail -n" in C. The "-n" option will be used to print the last n lines of a file - rather than the default option of printing the last 10 lines of a file. I wish to do this in a single pass. I can use lseek() to go to the end of the file. How to traverse backwards from there ? Is there any function that does this ? thanks, venkatesh