CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Location
    Chandigarh,India
    Posts
    11

    Question Need Code for these

    a c program to print last n lines if the text as well as n is specified in the program.

    the following program reads a file from BOF to EOF. I am looking for a program for reading from EOF to the number of lines i specify.i Can reach the end of file by using FSEEK() how do i read the lines.

    STORE FOPEN('test.txt') TO gnFileHandle && Open the file
    STORE FSEEK(gnFileHandle, 0, 2) TO gnEnd && Move pointer to EOF
    STORE FSEEK(gnFileHandle, 0) TO gnTop && Move pointer to BOF
    IF gnEnd <= 0 && Is file empty?
    WAIT WINDOW 'This file is empty!' NOWAIT
    ELSE && If not
    gcString = FGETS(gnFileHandle, gnEnd) && Store contents
    ? gcString
    ENDIF
    = FCLOSE(gnFileHandle) && Close the file
    Last edited by Amandeep; November 29th, 2002 at 04:41 AM.
    Regards,

    Aman

  2. #2
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    1. Attempt the homework on your own.
    2. If you have specific questions, ask. We'll be glad to help.

    Jeff

  3. #3
    Join Date
    May 2000
    Location
    Phoenix, AZ [USA]
    Posts
    1,347

    Re: Need Code for these

    Originally posted by Amandeep
    a c program to print last n lines if the text as well as n is specified in the program.
    What are you talking about? You want to print the last n lines
    of what text? You can let the user pass 'n' into your program.
    Research command-line arguments to programs ... more
    specifically the arguments to main() argc and argv.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured