Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
ReputationZh
V2EX  ›  Linux

Linux 下用 C 语言对二进制文件操作,我想删除末尾 16 位数据(不是清零是删除),应该怎么办?

  •  
  •   ReputationZh · Aug 6, 2020 · 3244 views
    This topic created in 2105 days ago, the information mentioned may be changed or developed.
    查阅了一上午资料,没找到解决办法 TAT 。
    8 replies    2020-08-06 14:58:19 +08:00
    fmumu
        1
    fmumu  
       Aug 6, 2020 via Android
    truncate ?
    zyffy
        2
    zyffy  
       Aug 6, 2020
    ftruncate
    tomychen
        3
    tomychen  
       Aug 6, 2020
    new_size = getfilesize()-16;// 自己实现
    fread(data,size, oldfile);
    fwrite(data, new_size,oldfile);//or newfile
    julyclyde
        4
    julyclyde  
       Aug 6, 2020
    删除?右移?
    ReputationZh
        5
    ReputationZh  
    OP
       Aug 6, 2020
    @zyffy 这个函数的第一个参数是 int ? 有没有具体用法。
    trn4
        6
    trn4  
       Aug 6, 2020 via iPhone
    @ReputationZh man truncate
    Cooky
        8
    Cooky  
       Aug 6, 2020 via Android
    truncate
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1252 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 23:38 · PVG 07:38 · LAX 16:38 · JFK 19:38
    ♥ Do have faith in what you're doing.