把一个文件拆成两个文件

把文件file1.txt拆分成两个文件file2.txt和file3.txt。

在主机Linux下调试成功;在用户板上调试,则拆分后的文件file2.txt和file3.txt尾部都少了部分数据,奇怪~~~~

 

程序代码:

#include <stdio.h>


main()
{
FILE *fd1,*fd2,*fd3;

unsigned addr,data;


fd1=fopen("/var/jffs2/file1.txt","r");
fd2=fopen("/var/jffs2/file2.txt","w");
fd3=fopen("/var/jffs2/file3.txt","w");


while(1)
   {
    fscanf(fd1,"%04x %04x/n",&addr,&data);
    if(addr==0x1111)

        break;
    else

        fprintf(fd2,"%04x %04x/n",addr&0xffff,data&0xffff);
   }

 

  while(fscanf(fd1,"%02x/n",&data)!=-1)
   {
        fprintf(fd3,"%02x/n",data&0xff);
   }
}

你可能感兴趣的:(linux,File)