码迷,mamicode.com
首页 > 其他好文 > 详细

代码示例_IO_fseek

时间:2019-06-24 12:33:35      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:pen   failed   center   src   字符   fopen   ESS   lib   ima   

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 !

 

代码示例_IO_fseek

标签:pen   failed   center   src   字符   fopen   ESS   lib   ima   

原文地址:https://www.cnblogs.com/panda-w/p/11076064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!