zoukankan      html  css  js  c++  java
  • 数据文件——之将文本文件定位到所需字符

    代码:

     1 //This is c program code!                                                                                           
     2 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     3   * 文档信息: *** :~/WORKM/stutyCode/cCode/recipesProblemSolution/chapter06/test6_20.c
     4   * 版权声明: *** :(魎魍魅魑)MIT
     5   * 联络信箱: *** :guochaoxxl@163.com
     6   * 创建时间: *** :2020年11月22日的下午01:12
     7   * 文档用途: *** :数据结构与算法分析-c语言描述
     8   * 作者信息: *** :guochaoxxl(http://cnblogs.com/guochaoxxl)
     9   * 修订时间: *** :2020年第46周 11月22日 星期日 下午01:12 (第327天)
    10   * 文件描述: *** :自行添加
    11  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    12 #include <stdio.h>
    13 
    14 void closeState(FILE *fPtr){
    15     int clo = fclose(fPtr);
    16     if(clo == -1){
    17         puts("file-closing failed.");
    18     }
    19     if(clo == 0){
    20         puts("file-closing successfully.");
    21     }
    22 }
    23 
    24 int  main(int argc, char **argv)
    25 {
    26     FILE *fPtr = fopen("pune.txt", "r");
    27     if(fPtr != NULL){
    28         puts("File pune.txt opened successfully.");
    29         
    30         puts("Let loc denotes current file position.");
    31         int loc = ftell(fPtr);
    32         printf("Now value of loc is %d
    ", loc);
    33 
    34         printf("Les us read a single character and it is: ");
    35         int ch = fgetc(fPtr);
    36         putchar(ch);
    37         printf("
    ");
    38 
    39         loc = ftell(fPtr);
    40         printf("Now value of loc is %d
    ", loc);
    41 
    42         fseek(fPtr, 8, 0);
    43         puts("Statement " fseek(fptr, 8, 0);" executed");
    44         loc = ftell(fPtr);
    45         printf("Now value of loc is %d
    ", loc);
    46 
    47         fseek(fPtr, 3, 1);
    48         puts("Statement " fseek(fptr, 3, 1);" executed");
    49         loc = ftell(fPtr);
    50         printf("Now value of loc is %d
    ", loc);
    51 
    52         fseek(fPtr, -5, 1);
    53         puts("Statement " fseek(fptr, -5, 1);" executed");
    54         loc = ftell(fPtr);
    55         printf("Now value of loc is %d
    ", loc);
    56 
    57         fseek(fPtr, -3, 2);
    58         puts("Statement " fseek(fptr, -3, 2);" executed");
    59         loc = ftell(fPtr);
    60         printf("Now value of loc is %d
    ", loc);
    61 
    62         fseek(fPtr, 0, 2);
    63         puts("Statement " fseek(fptr, 0, 2);" executed");
    64         loc = ftell(fPtr);
    65         printf("Now value of loc is %d
    ", loc);
    66 
    67         puts("Now let us perform a read operation.");
    68         ch = fgetc(fPtr);
    69         printf("Value read is %d
    ", ch);
    70         loc = ftell(fPtr);
    71         printf("Now value of loc is still %d
    ", loc);
    72 
    73         fseek(fPtr, 0, 0);
    74         puts("Statement " fseek(fptr, 0, 0);" executed");
    75         loc = ftell(fPtr);
    76         printf("Now value of loc is %d
    ", loc);
    77         puts("That's all.");
    78 
    79         closeState(fPtr);
    80     }else{
    81         puts("File-opening failed.");
    82     }
    83 
    84     return 0;
    85 }
  • 相关阅读:
    typro常用快捷键
    02: kali-linux破解密码运行脚本并隐藏进程
    01:kali安装使用
    01: 模拟挖矿黑客攻击过程
    12: docker-compose部署django+nginx+uwsgi+celery+redis+mysql
    11: Django + gunicorn + Nginx 的生产环境部署
    博客说明
    计算机中原码,反码,补码之间的关系
    修改linux下yum镜像源为国内镜像
    webp图片技术调研最终结论(完全真实数据可自行分析)
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/14054244.html
Copyright © 2011-2022 走看看