fseek

详情请看 http://www.cplusplus.com/reference/cstdio/fseek/

(1) fseek()

定义: int fseek ( FILE * stream, long int offset, int origin );

功能:重新设置stream的位置到offset处基于文件头/文件尾/当前位置

参数:stream: 只想一个文件对象的指针.

          offset:  二进制文件: Number of bytes to offset from origin.     文本文件: Either zero, or a value returned byftell.

          origin:  偏移基于的位置.

                     It is specified by one of the following constants defined in<cstdio> exclusively to be used as arguments for this function:

 ConstantReference position
SEEK_SET文件头
SEEK_CUR当前位置
SEEK_END文件
*

Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability).


返回值: 成功返回0 失败返回非0
/* fseek example */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  pFile = fopen ( "example.txt" , "wb" );
  fputs ( "This is an apple." , pFile );
  fseek ( pFile , 9 , SEEK_SET );
  fputs ( " sam" , pFile );
  fclose ( pFile );
  return 0;
}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值