zoukankan      html  css  js  c++  java
  • 94二进制操作函数

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    void test_write() {
    FILE*write = fopen("sats.db", "wb");
    if (!write) {
    printf("文件为空 ");
    system("pause");
    return;
    }
    int l_v1 = 0x10;
    int l_v2 = 0x9;
    fwrite(&l_v1, sizeof(int), 1, write);//数组也可以用
    fwrite(&l_v2, sizeof(int), 1, write);
    fclose(write);
    }
    void test_read() {
    FILE*read = fopen("sats.db", "rb");
    if (!read) {
    printf("文件为空 ");
    system("pause");
    return;
    }
    int l_v1 = NULL;
    int l_v2 = NULL;
    fread(&l_v1, sizeof(int), 1, read);
    fread(&l_v2, sizeof(int), 1, read);
    fclose(read);
    }
    void main() {
    //test_write();
    test_read();
    system("pause");
    }

    #include<stdlib.h>
    #include<stdio.h>
    #include<string.h>
    #include<sys/stat.h>
    void main(){
    struct stat l_stat={0};
    stat("1.txt",&l_stat);
    printf("文件大小:%d字节 ",l_stat.st_size);
    system("pause");
    }获取文件状态

    stat
    fgets、fputs、fprintf、fscanf
    这些函数是针对文本文件进行使用的,不允许对一些图片,音频,视频等非文字的文件进行使用.
    而且也没意义.

    fread和fwrite

    判断一个文件是不是文本文件的格式,只要打开notepad,把这个文件拖进来.
    如果可以正常显示,基本上可以确定为文本文件.

    但不管是文本文件,还是其他任何文件,我们都知道,其本质就是一堆0和1构成,最小单位都是1个字节.

  • 相关阅读:
    软件体系风格选择小结
    bert入门资料
    RNN入门和seq2seq
    推荐系统论文源码笔记——依次学习之DKN源码笔记
    Mac os下gcc编译错误解决方案
    ns3 安装方法
    angular http ajax header
    javascript 实现htmlEncode htmlDecode
    windows下的python扩展包下载地址
    php版DES
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9102754.html
Copyright © 2011-2022 走看看