Advertisement

LaTeX 两个辅助工具:统计中文字数及关闭 Acrobat 中的 PDF 文档

阅读量:

LaTeX 并未像 Word 这样预装中文字符计数功能,并且由于其源文件中存在大量控制字符,在没有专门工具的情况下无法通过文件大小推算其中包含多少个汉字。为此,在编写我的开源项目时我也遇到了这一问题,并因此开发出一个名为 cwc 的小型工具来解决这一需求。该程序仅在 count_files() 函数处采用了 Windows API 进程,并稍作改动即可移植到 Linux/Unix 系统上运行。

#include <stdio.h>
#include <wchar.h>
#include <windows.h>
int total_number = 0; // Total Chinese Characters

// UNICODE version word counter
void word_count_u(FILE* pf)
{
int w = 0, b = 2;
wint_t c;

while((c = getwc(pf)) != WEOF) {
b += 2; // byte count
if (c > 127) { // 中文字符
w++; // char count
}
}

printf("%10d /t %10d/n", w, b);
total += w;
}

// word counter
void w

全部评论 (0)

还没有任何评论哟~