fseek函数c语言

C中的fseek()函数 (fseek() function in C)

Prototype:

原型:

    int feek(FILE *stream, long int offset, int origin);

Parameters:

参数:

    FILE *stream, long int offset, int origin

Return type: int

返回类型: int

Use of function:

使用功能:

The fseek() function is used to set the file indicator pointer to the associate with the file stream according to the value of offset and starting point of the file. The prototype of the function fseek() is:

fseek()函数用于根据文件的偏移量和起点将文件指示符指针设置为与文件流相关联。 函数fseek()的原型为:

    int feek(FILE *stream, long int offset, int origin);

Here, the offset is number of bytes from the origin.

在这里, 偏移量是从原点起的字节数。

There are three macros in fseek() function:

fseek()函数中包含三个宏:

  1. SEEK_SET: Seek from start of file

    SEEK_SET:从文件开头查找

  2. SEEK_CUR: Seek from current location

    SEEK_CUR:从当前位置寻求

  3. SEEK_END: Seek from end of file

    SEEK_END:从文件末尾查找

C语言中的fseek()示例 (fseek() example in C)

#include <stdio.h>
#include <stdlib.h>
int main(){//Initialize the file pointer
FILE *f;
//Take a array of characters
char ch[100];
//Create the file for write operation
f=fopen("includehelp.txt","w");
printf("Enter five strings\n");
for(int i=0;i<4;i++){//take the strings from the users
scanf("%[^\n]",&ch);
//write back to the file
fputs(ch,f);
//every time take a new line for the new entry string
//except for last entry.Otherwise print the last line twice
fputs("\n",f);
//clear the stdin stream buffer
fflush(stdin);
}
//take the strings from the users
scanf("%[^\n]",&ch);
fputs(ch,f);
//close the file after write operation is over
fclose(f);
//open a file
f=fopen("includehelp.txt","r");
printf("\n...............print the strings..............\n");
while(!feof(f)){//takes the first 100 character in the character array
fgets(ch,100,f);
//and print the strings
printf("%s",ch);
}
rewind(f);
printf("\n...............print the position before print a strings S..............\n");
fseek(f,0,SEEK_SET);
printf("the file indicator position is - %d\n",ftell(f));
printf("\n...............print the position after print a strings ..............\n");
fgets(ch,100,f);
printf("%s",ch);
fseek(f,0,SEEK_CUR);
//print the current location
printf("the file indicator position is - %d\n",ftell(f));
printf("\n...............print the position after print all the strings ..............\n");
fseek(f,0,SEEK_END);
printf("the file indicator position is - %d\n",ftell(f));
//close the file
fclose(f);
return 0;
}

Output

输出量

翻译自: https://www.includehelp.com/c-programs/fseek-function-in-c-language-with-example.aspx

fseek函数c语言

fseek函数c语言_使用示例的C语言中的fseek()函数相关推荐

  1. c语言feof函数_使用示例的C语言中的feof()函数

    c语言feof函数 C语言中的feof()函数 (feof() function in C) Prototype: 原型: int feof(FILE* filename); Parameters: ...

  2. main c语言中变量的定义,C语言中在main函数中定义的变量是全局变量么_后端开发...

    PHP 和 JavaSript 区别_后端开发 PHP是一种创建动态交互性站点的强有力的服务器端脚本语言,主要用于Web开发领域,而JavaSript是一种具有函数优先的轻量级,解释型或即时编译型的高 ...

  3. c++freopen函数_使用示例的C语言中的freopen()函数

    c++freopen函数 C语言中的freopen()函数 (freopen() function in C) Prototype: 原型: FILE* freopen(const char *str ...

  4. fopen函数的用法示例_使用示例的C语言中的fopen()函数

    fopen函数的用法示例 C语言中的fopen()函数 (fopen() function in C) Prototype: 原型: FILE *fopen(const char* filename, ...

  5. c语言strlen用法,如何使用c语言中的strlen()函数

    c语言中strlen()函数的用法是:[strlen(const char *str)].该函数用于计算字符串的长度,直到空结束字符,但不包括结束字符,并返回字符串的长度. 函数介绍: (推荐教程:c ...

  6. fclose函数_使用示例的C语言中的fclose()函数

    fclose函数 C中的fclose()函数 (fclose() function in C) Prototype: 原型: int fclose(FILE *filename); Parameter ...

  7. c语言getchar函数_C语言中带有示例的getchar()函数

    c语言getchar函数 C语言中的getchar()函数 (getchar() function in C) The getchar() function is defined in the < ...

  8. c语言自动生成系统时间函数,使用C语言中的time函数获取系统时间

    使用C语言中的time函数获取系统时间 可以通过time()函数来获得计算机系统当前的日历时间(Calendar Time),处理日期时间的函数都是以本函数的返回值为基础进行运算.其原型为: time ...

  9. c语言中的printf函数_C语言中的printf()函数与示例

    c语言中的printf函数 C语言中的printf()函数 (printf() function in C) The printf() function is defined in the <s ...

  10. c语言里面gets(a)是什么意思,C语言中的gets()函数

    在c语言中读取字符串有多种方法,比如scanf() 配合%s使用,但是这种方法只能获取一个单词,即遇到空格等空字符就会返回.如果要读取一行字符串, 比如:I love MIT 这种情况,scanf() ...

最新文章

  1. Spring Framework 5.3.6、5.2.14 发布
  2. crontab脚本,定时任务相关细节
  3. sklearn逻辑回归 极大似然 损失_收藏!攻克目标检测难点秘籍二,非极大值抑制与回归损失优化之路...
  4. eWebEditor不支持IE8的解决方法
  5. volumio怎么连接屏幕_电视机维修电话|电视开起一闪一闪的,是怎么回事?
  6. what you should do if you want to exercise?
  7. 安装java环境linux和windows
  8. 在windows中手动安装第三方模块
  9. 论文学习10-Joint entity recognition and relation extraction as a multi-head selection problem(实体关系联合抽取模型
  10. 酷狗音乐linux版_酷狗音乐概念版APP内测获用户好评:极简化,更高级
  11. nohup方式 真正的后台不挂断运行程序
  12. UML统一建模语言是什么?
  13. 大数据高级开发工程师——大数据相关工具之一 Sqoop
  14. RHCE培训多少钱?
  15. AOP和整合mybatis
  16. Python-Django-视图
  17. 不会英语能学Java吗?
  18. 飞车手游显示服务器连接失败怎么办,QQ飞车手游拉取服务器失败 请检查网络稍后重试...
  19. 0英文基础能学计算机编程么,我零基础,英语和数学都不好,能学会编程吗?...
  20. caffe层解析之softmaxwithloss层

热门文章

  1. [原创]编程实现UCDOS字库的显示和打印
  2. 天涯论坛邮箱采集器1.0
  3. ApacheCN - 关于我们
  4. 电力系统绝缘配合方法
  5. 在计算机图形学中多边形的表示方法通常有,计算机图形学复习大纲
  6. 因子分析 factor analysis (二 ) : 因子分析模型
  7. day13、1 - 抓包--科来软件使用
  8. Android C++ OpenGL教程课程总结
  9. 强行进入加密QQ空间
  10. MATLAB 求导、符号计算