《Linux系统编程》笔记 第三章(二)
发布时间:2020-12-13 21:12:48 所属栏目:PHP教程 来源:网络整理
导读:3.6 定位流 标准库提供了与系统调用lseek()类似的函数来定位流中的读写位置。 #include stdio.h int fseek (FILE *stream, long offset, int whence); long ftell(FILE *stream); 与lseek()用法类似,whence提供了以下选择: SEEK_CUR -将流的读写位置设置为
3.6 定位流标准库提供了与系统调用lseek()类似的函数来定位流中的读写位置。 #include <stdio.h>
int fseek (FILE *stream,long offset,int whence);
long ftell(FILE *stream); 与lseek()用法类似,whence提供了以下选择: 上述的函数中偏移量类型是long,若处理的文件大小超过long变量的范围时,可使用 #include <stdio.h>
int fseeko(FILE *stream,off_t offset,int whence);
off_t ftello(FILE *stream); off_t在64位系统上被实现为64位大小,在32位系统上与long大小相同。 类似功能的函数有 #include <stdio.h>
int fsetpos (FILE *stream,fpos_t *pos);
int fgetpos(FILE *stream,fpos_t *pos); 除非为了源码兼容性,1般不使用这个函数。 #include <stdio.h>
void rewind (FILE *stream); 该调用将stream的读写位置设置为流初始,与 格式化I/O格式化I/O是指将内容依照规定的格式整理后读取或输出。 #include <stdio.h>
int printf(const char *format,...);//格式化到标准输出
int fprintf(FILE *stream,const char *format,...);//格式化到流
int sprintf(char *str,...);//格式化到str中
int snprintf(char *str,size_t size,...);//与sprintf类似,更安全,其提供了可写缓冲区的长度
int dprintf(int fd,...);//格式化到文件描写符fd对应的文件中 上述函数的返回值均是真正格式化的长度,不包括字符串结束符 |