代码示例_标准IO_fseek

 2023-09-09 阅读 22 评论 0

摘要:fseek fseek.c 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 // 打开/创建 7 FILE *fp = fopen("./1.text","w+"); 8 if(fp==NULL){ 9 perror("fopen failed"); 10 exit(1); 11 } 12 13 // 写

fseek


 

fseek.c

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main(void)
 5 {
 6     // 打开/创建
 7     FILE *fp = fopen("./1.text","w+");
 8     if(fp==NULL){
 9         perror("fopen failed");
10         exit(1);
11     }
12 
13     // 写字符串
14     fputs("panda_w",fp);
15 
16 
17     // 文件定位
18     fseek(fp,2,SEEK_SET);      //将文件流位置置开头,并且移动两位!
19 
20 
21     // 读字符
22     int p = fgetc(fp);
23     if(p==EOF){
24         perror("fgetc failed");
25         exit(1);
26     }
27     printf("read : %c\n",p);
28     
29 
30     // 关闭
31     fclose(fp);
32 
33     return 0 ;
34 }

 

测试:


 

 

 

success !

 

转载于:https://www.cnblogs.com/panda-w/p/11076064.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/31725.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息