首页 > 其他 > 详细

代码示例_IO_fput / fget

时间:2019-06-24 10:22:35      阅读:193      评论:0      收藏:0      [点我收藏+]

 

fput / fget

 


 

fput_fget.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     int num = 66;
15     if(  fputc(num,fp)== EOF  ){
16         perror("fputc failed");
17         exit(1);
18     }
19     
20     // 关闭
21     fclose(fp);
22 
23 
24     // 打开/创建
25     fp = fopen("./1.text","r");
26     if(fp==NULL){
27         perror("fopen failed");
28         exit(1);
29     }
30     
31     // 读字符
32     int p = fgetc(fp);
33     if(p==EOF){
34         perror("fgetc failed");
35         exit(1);
36     }
37     printf("read : %c\n",p);
38 
39 
40     // 关闭
41     fclose(fp);
42 
43 
44     return 0 ;
45 }

 

 

测试:


 

 

技术分享图片

 

 

success !

 

代码示例_IO_fput / fget

原文:https://www.cnblogs.com/panda-w/p/11075389.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!