且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C从文件中删除最后n个字符

更新时间:2023-02-04 23:18:35

为什么不使用:

   #include <unistd.h>
   #include <sys/types.h>

   int truncate(const char *path, off_t length);
   int ftruncate(int fd, off_t length);

例如:

    charsToDelete = 5;
    fseeko(InputFile,-charsToDelete,SEEK_END);
    position = ftello(InputFile);
    ftruncate(fileno(InputFile), position);