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个字节.

  • 相关阅读:
    Go:获取命令行参数
    Go:文件操作
    Go:类型断言
    GO:interface
    Go:面向"对象"
    Go:工厂模式
    layui中流加载layui.flow
    js显示当前时间
    layui中的分页laypage
    layui中的多图上传
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/9102754.html
Copyright © 2011-2022 走看看