私は長い間 c でコードを書こうとしていましたが、プログラムの目的は 1) 引数として受け取ったテキスト ファイルの最後の 10 行を出力することです。2) 表示エラー。それ以外の場合は、シーク コマンドに問題があり、修正中に失われます。
#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);
}
}
}
}
これがエラーです。
操作可能なプログラムまたはバッチ ファイル。'seek' は、内部コマンドまたは外部コマンド、操作可能なプログラムまたはバッチ ファイルとして認識されません。