lseek.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 36 行

C
36
字号

long int file_posn;
int handle;

/* get current file position */
file_posn = lseek( handle, 0L, SEEK_CUR );
  /* or */
file_posn = tell( handle );

/* return to previous file position */
file_posn = lseek( handle, file_posn, SEEK_SET );


#include <stdio.h>
#include <io.h>

int read_record( int  handle,
                 long rec_numb,
                 int  rec_size,
                 char *buffer )
  {
    if( lseek( handle, rec_numb * rec_size, SEEK_SET )
         == -1L ) {
      return( -1 );
    }
    return( read( handle, buffer, rec_size ) );
  }

.blktext begin
The function in this example assumes records are numbered starting
with zero and that
.arg rec_size
contains the size of a record in the file
(including the carriage-return character in text files).
.blktext end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?