_tell _telli64
取得檔案的指標的位置。
long _tell(
int handle
);
__int64 _telli64(
int handle
);
參數
- handle
檔案描述項指的開啟的檔案。
傳回值
檔案指標目前位置。在裝置上的搜尋觀念,傳回的值未定義。
傳回值為 –1L 表示發生錯誤。如果handle是無效的檔案描述項無效的參數處理常式會叫用,如所述參數驗證。如果執行,則允許繼續執行,這些函式會設定errno到EBADF ,並傳回-1 L。
請參閱 _doserrno、 errno、 _sys_errlist,以及 _sys_nerr 如需有關篩選器及其他的詳細資訊,任何傳回碼。
備註
_tell函式取得檔案的指標 (如果有的話) 的目前位置,關聯handle引數。位置被以從檔案開頭的位元組數目。對於_telli64函式中,這個值以 64 位元整數來表示。
需求
常式 |
所需的標頭 |
---|---|
_tell, _telli64 |
<io.h> |
其他的相容性資訊,請參閱相容性在簡介中。
範例
// crt_tell.c
// This program uses _tell to tell the
// file pointer position after a file read.
//
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <share.h>
#include <string.h>
int main( void )
{
int fh;
char buffer[500];
if ( _sopen_s( &fh, "crt_tell.txt", _O_RDONLY, _SH_DENYNO, 0) )
{
char buff[50];
_strerror_s( buff, sizeof(buff), NULL );
printf( buff );
exit( -1 );
}
if( _read( fh, buffer, 500 ) > 0 )
printf( "Current file position is: %d\n", _tell( fh ) );
_close( fh );
}
輸入: crt_tell.txt
Line one.
Line two.
Output
Current file position is: 20