Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15568
  • 博文数量: 7
  • 博客积分: 280
  • 博客等级: 二等列兵
  • 技术积分: 80
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-25 17:51
文章分类
文章存档

2008年(7)

我的朋友
最近访客

分类: C/C++

2008-07-10 08:33:23

用Ipod nano3看TXT只支持4K,郁闷,自己动手写个文本分割工具吧。
 
建立MFC对话框程序,主要分割代码如下
 

bool CipodtxtDlg::split(void)
{
    CString cs, out, tmp;
    CFile cif, cof;
    CFileException ex;
    char buffer[4096] = { 0 };
    char *p;
    int nread, n;

    GetDlgItemText(IDC_EDIT1, cs);

    if(!cif.Open(cs, CFile::modeRead, &ex))
    {
        return false;
    }
    tmp = cs.Mid(0, cs.ReverseFind('.'));

    int nfile = (int)(cif.GetLength() / 4096) + 1;
    for(int i=0; nread=cif.Read(buffer, 4096), nread>0;++i)
    {
        out.Format(_TEXT("%s_%.8d.txt"), (LPCTSTR)tmp, i);
        if(cof.Open(out, CFile::modeCreate|CFile::modeWrite, &ex))
        {
            p = buffer+4095;
            n = 0;

            //如果最后一个字节不是完整汉字,本文件放弃,由下一个文件输出。
            while(!isascii(*p) && p!=buffer)
            {
                p--;
                n++;
            }
            if(n%2==1)
            {
                nread--;
                cif.Seek(-1, CFile::current);
            }

            cof.Write(buffer, nread);
            cof.Close();
            memset(buffer, 0, 4096);
        }
        m_pc.SetPos(i*100/nfile);
    }

    cif.Close();
    m_pc.SetPos(100);
    return true;
}

阅读(568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~