About the Usage of fseek and ftell
来源:互联网 发布:阿里云怎么修改镜像 编辑:程序博客网 时间:2024/05/16 01:50
The following is a simple program that accomplishs the division of one file into two parts, in which what should be concerned is the usage of two function, fseek and ftell.
[1] fseek
Header
<cstdio>
int fseek ( FILE * stream, long int offset, int origin );
Reposition stream position indicator
Sets the position indicator associated with the stream to a new position defined by adding offset to a reference position specified by origin.
The End-of-File internal indicator of the stream is cleared after a call to this function, and all effects from previous calls to ungetc are dropped.
When using fseek on text files with offset values other than zero or values retrieved with ftell, bear in mind that on some platforms some format transformations occur with text files which can lead to unexpected repositioning.
On streams open for update (read+write), a call to fseek allows to switch between reading and writing.
Parameters
stream
Pointer to a FILE object that identifies the stream.
offset
Number of bytes to offset from origin.
origin
Position from where offset is added. It is specified by one of the following constants defined in <cstdio>:
SEEK_SET Beginning of file
SEEK_CUR Current position of the file pointer
SEEK_END End of file
Return Value
If successful, the function returns a zero value. Otherwise, it returns nonzero value.
[2] ftell
Header
<cstdio>
long int ftell ( FILE * stream );
Get current position in stream
Returns the current value of the position indicator of the stream.
For binary streams, the value returned corresponds to the number of bytes from the beginning of the file.
For text streams, the value is not guaranteed to be the exact number of bytes from the beginning of the file, but the value returned can still be used to restore the position indicator to this position using fseek.
Parameters
stream
Pointer to a FILE object that identifies the stream.
Return Value
On success, the current value of the position indicator is returned.
If an error occurs, -1L is returned, and the global variable errno is set to a positive value. This value can be interpreted by perror.
code:
I will do appreciate what suggestion you give me, thx!
- About the Usage of fseek and ftell
- fseek,ftell
- 【DataStructure】The description and usage of Stack
- the principle and usage of va_list
- The installation and usage of Auto-jump and ZSH
- About the application of lambda and relayCommand
- fseek与ftell函数
- fseek和ftell
- fseek与ftell函数
- fseek与ftell函数
- ftell\fseek\rewind函数
- ftell()和fseek()
- fseek,ftell,fprintf
- fseek、ftell、fread、fwrite
- fseek ftell rewind
- ftell,fseek,rewind
- fseek和ftell
- usage of >>>、>> and << operators
- Javascript 文件操作 实现方法小结
- linux skills
- asp数据库操作
- Oracle大批量删除数据方法
- 用rand()和srand()产生为随机数的方法总结
- About the Usage of fseek and ftell
- 格林时间和DateTime标准格式进行转换
- today , flex sdk3.5 is out
- 一道上机题
- vi/vim 快捷键盘对照图(含中英文)
- 个人简历常用到的英语
- (转)对日软件程序员的职业前景分析
- 用mapXtreme Java开发web gis应用 (上)
- 求教Eclipse关于数据绑定的问题