Code Example _IO_fput / fget

 

fput / fget

 


 

fput_fget.c

 

. 1 #include <stdio.h>
 2 #include <stdlib.h>
 . 3  
. 4  int main ( void )
 . 5  {
 . 6      // Open / Create 
. 7      the FILE * FP = the fopen ( " ./1.text " , " W + " ) ;
 . 8      IF (FP == NULL) {
 . 9          perror ( " the fopen failed " );
 10          Exit ( . 1 );
 . 11      }
 12 is      
13 is      // write characters 
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 }

 

 

test:


 

 

 

 

success !

 

Guess you like

Origin www.cnblogs.com/panda-w/p/11075389.html