C program to write last few lines of program, seek error?
I was trying to write a code in c after long time, objective of program is to
1) print the last 10 lines of text file which is received as arguements. 
2) display errors otherwise
there is a problem with seek command which is got lost correcting it. 

    
<pre><code>
#include <stdio.h>
#include <stdlib.h>

int main ( int argc, char *argv[] )
{
    char buffer[20],c;
    int bytes =512,flag=0;
    if ( argc != 2 ) /* argc should be 2 for correct execution */
    {
        /* We print argv[0] assuming it is the program name */
        printf( "usage: %s filename", argv[0] );
    }
    else 
    {
        // We assume argv[1] is a filename to open
        FILE *file = fopen( argv[1], "r" );
        
        /* fopen returns 0, the NULL pointer, on failure */
        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }
        else 
        {
             while (1)
             {
                   sprintf (buffer, "seek(file,%d,0)", bytes);
                   system(buffer);
                   while ( (c=fgetc(file))!= EOF)
                   {
                         if(c=='\n')
                         {
                              flag++;
                         }
                   }
                   if (flag >= 10)
                      bytes=bytes*2;
                   else 
                        break;
             }
             
             flag-=10;
             sprintf (buffer, "seek(file,%d,0)", bytes);
             system(buffer);
             while(flag > 0)
             {
                  if((c=fgetc(file))=='\n')
                  {
                         flag--;
                  }
             }
             while ( (c=fgetc(file))!= EOF)
             {
                         printf("%c",c);
             }
        }
    }
}
                   
</code>   
</pre>          
Here's the error, 

operable program or batch file.
'seek' is not recognized as an internal or external command,
operable program or batch file.

                   
                   
                   

C program to write last few lines of program, seek error?
===

I was trying to write a code in c after long time, objective of program is to
1) print the last 10 lines of text file which is received as arguements. 
2) display errors otherwise
there is a problem with seek command which is got lost correcting it. 

    
<pre><code>
#include <stdio.h>
#include <stdlib.h>

int main ( int argc, char *argv[] )
{
    char buffer[20],c;
    int bytes =512,flag=0;
    if ( argc != 2 ) /* argc should be 2 for correct execution */
    {
        /* We print argv[0] assuming it is the program name */
        printf( "usage: %s filename", argv[0] );
    }
    else 
    {
        // We assume argv[1] is a filename to open
        FILE *file = fopen( argv[1], "r" );
        
        /* fopen returns 0, the NULL pointer, on failure */
        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }
        else 
        {
             while (1)
             {
                   sprintf (buffer, "seek(file,%d,0)", bytes);
                   system(buffer);
                   while ( (c=fgetc(file))!= EOF)
                   {
                         if(c=='\n')
                         {
                              flag++;
                         }
                   }
                   if (flag >= 10)
                      bytes=bytes*2;
                   else 
                        break;
             }
             
             flag-=10;
             sprintf (buffer, "seek(file,%d,0)", bytes);
             system(buffer);
             while(flag > 0)
             {
                  if((c=fgetc(file))=='\n')
                  {
                         flag--;
                  }
             }
             while ( (c=fgetc(file))!= EOF)
             {
                         printf("%c",c);
             }
        }
    }
}
                   
</code>   
</pre>          
Here's the error, 

operable program or batch file.
'seek' is not recognized as an internal or external command,
operable program or batch file.

                   
                   
                   
