代码之家  ›  专栏  ›  技术社区  ›  Delan Azabani

奇数追加行为

  •  0
  • Delan Azabani  · 技术社区  · 14 年前

    如果我有一个包含

    manual
    /lib/plymouth/themes/default.plymouth
    
    /lib/plymouth/themes/spinfinity/spinfinity.plymouth
    10
    /lib/plymouth/themes/ubuntu-logo/ubuntu-logo.plymouth
    100
    
    

    然后我打开它 a 模式,然后执行

    fprintf(f, "/el/derpito.plymouth\n100\n");
    

    为什么文件现在包含这个?

    manual
    /lib/plymouth/themes/default.plymouth
    
    /lib/plymouth/themes/spinfinity/spinfinity.plymouth
    10
    /lib/plymouth/themes/ubuntu-logo/ubuntu-logo.plymouth
    100
    
    /el/derpito.plymouth
    100

    我希望文件是这样的:

    manual
    /lib/plymouth/themes/default.plymouth
    
    /lib/plymouth/themes/spinfinity/spinfinity.plymouth
    10
    /lib/plymouth/themes/ubuntu-logo/ubuntu-logo.plymouth
    100
    /el/derpito.plymouth
    100
    
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   San Jacinto    14 年前

    在您进行写入之前,可能有一个孤独的\n或\cr卡在文件的末尾。我要用十六进制编辑器打开它,然后看。

        2
  •  0
  •   sum1stolemyname    14 年前

    我的第一个猜测是,文件的最后一个字符(在追加之前)是换行符,在换行符之后追加追加新行。