rewind
重新定位文件指针到文件开头。
void rewind(
FILE *stream
);
参数
- stream
指向 FILE 结构的指针。
备注
倒带 函数重新定位文件指针与 stream 语句添加到文件开头。 对 倒带 的一个调用相似。
(void) fseek( stream**,** 0L, SEEK_SET );
但是,与 fseek不同的是,倒带 的错误指示器和清除流文件尾指示符。 此外,与 fseek不同的是,倒带 不返回值指明指针是否成功移动。
清除键盘缓冲区,用 stdin的流使用与键盘默认情况下,倒带
如果 NULL是指针,无效参数处理器程序,将按 参数验证中所述进行调用。 如果允许执行继续,则这些函数将返回并将errno设置为 EINVAL。
有关这些属性和其他错误代码的信息,请参见 _doserrno、errno、_sys_errlist 和 _sys_nerr。
要求
例程 |
必需的标头 |
---|---|
rewind |
<stdio.h> |
有关其他兼容性信息,请参见“简介”中的兼容性。
库
C 运行时库的所有版本。
示例
// crt_rewind.c
/* This program first opens a file named
* crt_rewind.out for input and output and writes two
* integers to the file. Next, it uses rewind to
* reposition the file pointer to the beginning of
* the file and reads the data back in.
*/
#include <stdio.h>
int main( void )
{
FILE *stream;
int data1, data2;
data1 = 1;
data2 = -37;
fopen_s( &stream, "crt_rewind.out", "w+" );
if( stream != NULL )
{
fprintf( stream, "%d %d", data1, data2 );
printf( "The values written are: %d and %d\n", data1, data2 );
rewind( stream );
fscanf_s( stream, "%d %d", &data1, &data2 );
printf( "The values read are: %d and %d\n", data1, data2 );
fclose( stream );
}
}
Output
The values written are: 1 and -37
The values read are: 1 and -37
.NET Framework 等效项
不适用。若要调用标准 C 函数,请使用 PInvoke。有关更多信息,请参见平台调用示例。