convert.cpp

代码
// convert.cpp : 定义控制台应用程序的入口点。
//

#include 
"stdafx.h"
#include 
<stdlib.h>
#include 
<string.h>

int _tmain(int argc, _TCHAR* argv[])
{
 FILE   
*fp1;   //文件指针
 FILE   *fp2;   
 
char buf[1024];//缓冲区 
 if(NULL == (fp1 = fopen("utf8.tab","r")))
 {
  exit(
-1);
 }
 
else
 {
  
char *p1;
  unsigned 
short d1;
  unsigned 
long d2;
  
char ch;

  
if(NULL == (fp2 = fopen("txt.txt","w+")))
  {
   printf(
"打开文件失败\n");
   exit(
-1);
  }

  
while(1)
  {
   
if(NULL == fgets(buf,sizeof(buf)-1,fp1)) 
    
break;
   p1
=buf;
   memcpy(
&d1,buf,2);
   
if(6 == strlen(p1))
   {
    memcpy(
&d2,buf+2,3);
   }
   
if(5 == strlen(p1))
   { 
    memcpy(
&d2,buf+2,2); 
   }
   fwrite(
&d1,2,1,fp2);
   fwrite(
&d2,3,1,fp2);
  }
  fclose(fp2);
 }
 
return 0;
}

 
原文地址:https://www.cnblogs.com/kakaliush/p/1624763.html