[分享] 我寫了一支處理許功蓋問題的程式
參考之前的相關文章和一個別人寫的 function
綜合自己的需求寫出此程式
需要的人就拿去用
若有可以改進的地方請用力指正我
感激
/*
作者: Logo Guo
日期: 2006/03/19
環境: fedora core 3 linux / g++ 3.4.4
功能: 處理許功蓋問題 透過此程式處理許功蓋問題的檔案
版本: 1.0
信箱: logo@sunkill.homelinux.net
*/
#include <iostream>
#include <fstream>
using namespace std;
int big5_code(unsigned char hb, unsigned char lb);
int main(int argc, char* argv[])
{
if(argc != 3)
{
cout << "說明: " << argv[0] << " [source file] [result file]" << endl;
exit(1);
}
else
{
ifstream fin(argv[1], ios::in);
if(!fin)
{
cout << "檔案 " << argv[1] << " 開起失敗或不存在" << endl;
exit(1);
}
ifstream fout(argv[2], ios::in);
if(fout)
{
fin.close();
fout.close();
cout << "檔案 " << argv[2] << " 開起失敗或已存在" << endl;
exit(1);
}
else
{
ofstream fout(argv[2], ios::out);
if(!fout)
{
fin.close();
cout << "檔案 " << argv[2] << " 開起失敗或已存在" << endl;
exit(1);
}
unsigned char ch1, ch2;
bool flag = false;
while(fin.peek() != EOF)
{
ch1 = fin.get();
if(fin.peek() == EOF) break;
ch2 = fin.get();
if(big5_code(ch1, ch2) && ch2 == '\\') flag = true;
if(flag)
{
fout << ch1 << ch2 << '\\';
flag = false;
continue;
}
fout.put(ch1);
fin.putback(ch2);
}
fout << endl;
}
fin.close();
fout.close();
}
cout << "處理完成 " << argv[1] << " -> " << argv[2] << endl;
return 0;
}
int big5_code(unsigned char hb, unsigned char lb)
{
int hadd,ladd;
unsigned int big5;
big5 = lb + (hb << 8);
if((lb <= 0x7e && lb >= 0x40 || lb <= 0xfe && lb >= 0xa1) && (big5 >= 0xa440
&& big5 <= 0xc67e || big5 <= 0xf9fe && big5 >= 0xc940))
{
hadd = (hb - 164) * 157;
ladd = (lb < 127) ? (lb - 64) : (lb - 161 + 63);
return 1;
}
return 0;
}
--
for(i=不懂;i!=了解;i++)
{
......
......
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.67.101.226
推
03/19 16:58, , 1F
03/19 16:58, 1F
推
03/19 16:59, , 2F
03/19 16:59, 2F
推
03/19 17:15, , 3F
03/19 17:15, 3F
推
03/19 20:15, , 4F
03/19 20:15, 4F
推
03/20 10:47, , 5F
03/20 10:47, 5F
→
03/20 10:49, , 6F
03/20 10:49, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章