zoukankan      html  css  js  c++  java
  • 代码示例_标准IO_fseek

    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
    ",p);
    28     
    29 
    30     // 关闭
    31     fclose(fp);
    32 
    33     return 0 ;
    34 }

    测试:


    success !

    Stay hungry, stay foolish 待续。。。
  • 相关阅读:
    qt动态加载UI文件
    Qt常见控件和操作
    MySQL
    tomcat
    linux iptables基础
    linux 网络基础
    linux CA及OpenSSL学习
    k8s 访问控制
    k8s 存储卷
    docker 安装部署
  • 原文地址:https://www.cnblogs.com/panda-w/p/11076064.html
Copyright © 2011-2022 走看看