/* ECP: FILEname=fig12_16.c */ /* 1*/ #include /* 2*/ #include /* 3*/ /* Print Last HowMany Characters in FileName */ /* 4*/ void /* 5*/ LastChars( const char *FileName, unsigned int HowMany ) /* 6*/ { /* 7*/ FILE *Fp; /* 8*/ char *Buffer; /* 9*/ int CharsRead; /*10*/ int FileSize; /*11*/ if( ( Buffer = malloc( HowMany ) ) == NULL ) /*12*/ { /*13*/ fprintf( stderr, "Out of space!!\n" ); /*14*/ return; /*15*/ } /*16*/ if( ( Fp = fopen( FileName, "rb" ) ) == NULL ) /*17*/ fprintf( stderr, "Can not open %s\n", FileName ); /*18*/ else /*19*/ { /*20*/ /* Get The Size Of The File */ /*21*/ fseek( Fp, 0, SEEK_END ); /*22*/ FileSize = ftell( Fp ); /*23*/ if( FileSize < HowMany ) /*24*/ HowMany = FileSize; /*25*/ /* Copy Its End */ /*26*/ fseek( Fp, - HowMany, SEEK_END ); /*27*/ CharsRead = fread( Buffer, 1, HowMany, Fp ); /*28*/ fwrite( Buffer, 1, CharsRead, stdout ); /*29*/ fclose( Fp ); /*30*/ } /*31*/ free( Buffer ); /*32*/ }