c语言 压缩txt文件的函数,c语言 文本文件压缩

你到底用二进制写 还是用ASCII码写文件,你打开时记事本使用的是ASCII码。

用二进制方式创建文件,文件开头需要写入0xff、0xfe两个字节,然后再写Unicode字符串(也是按二进制数据写入)。

fwprintf需要一个FILE句柄,关键是看你创建FILE句柄时是否让这个文件以UNICODE形式存储数据了。类似:

FILE* fileHandle;

// Create an the xml file in text and Unicode encoding mode.

if ((fileHandle = _wfopen( L"_wfopen_test.xml",L"wt+,ccs=UNICODE")) == NULL) // C4996

// Note: _wfopen is deprecated; consider using _wfopen_s instead

{

...........

}

下面的示例来自MSDN:

// crt__wfopen.c

// compile with: /W3

// This program creates a file (or overwrites one if

// it exists), in text mode using Unicode encoding.

// It then writes two strings into the file

// and then closes the file.

#include

#include

#include

#include

#define BUFFER_SIZE 50

int main(int argc, char** argv)

{

wchar_t str[BUFFER_SIZE];

size_t strSize;

FILE* fileHandle;

// Create an the xml file in text and Unicode encoding mode.

if ((fileHandle = _wfopen( L"_wfopen_test.xml",L"wt+,ccs=UNICODE")) == NULL) // C4996

// Note: _wfopen is deprecated; consider using _wfopen_s instead

{

wprintf(L"_wfopen failed!\n");

return(0);

}

// Write a string into the file.

wcscpy_s(str, sizeof(str)/sizeof(wchar_t), L"\n");

strSize = wcslen(str);

if (fwrite(str, sizeof(wchar_t), strSize, fileHandle) != strSize)

{

wprintf(L"fwrite failed!\n");

}

// Write a string into the file.

wcscpy_s(str, sizeof(str)/sizeof(wchar_t), L"");

strSize = wcslen(str);

if (fwrite(str, sizeof(wchar_t), strSize, fileHandle) != strSize)

{

wprintf(L"fwrite failed!\n");

}

// Close the file.

if (fclose(fileHandle))

{

wprintf(L"fclose failed!\n");

}

return 0;

}

这个

取消

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值