rewind

重新定位文件指向文件的开头。

void rewind(
   FILE *stream 
);

参数

  • stream
    文件 结构的指针。

备注

倒带 函数重新定位文件指针与 stream 到文件的开头。 为 倒带 的调用相似。

(无效 () fseek stream**,0L,** SEEK_SET);

但是,与 fseek倒带 清除流以及文件结尾指示符的错误指示器。 此外,不同 fseek倒带 不返回值指示指针是否已成功移动。

清除键盘区域,与流 stdin的使用 倒带 ,默认情况下与键盘。

如果流是 NULL 指针,无效参数调用处理程序,如 参数验证所述。 如果执行允许继续,此函数返回,并 errno 设置为 EINVAL。

有关这些属性和其他错误代码的信息,请参见 _doserrno、 errno、 _sys_errlist 和 _sys_nerr

要求

实例

必需的头

倒带

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。有关更多信息,请参见 平台调用示例

请参见

参考

流I/O