代码示例_标准IO_fputc / fgetc

 

fputc / fgetc

 


 

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 !

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值