liunux环境编译命令:
gcc test.cpp -o test
test.cpp 文件:
instring 为需要被分割的文件:
outstring 为分割后的文件:
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h> // Contains POSIX terminal control definitions
#define BUF_LENGTH 0x1869ff
int main(int argc, char * argv[])
{
char *instring="./POTKCheck_00199D_0435_20000001_100000_20240321.chk";
char *outstring="./POTKCheck_00199D_0435_20000001_100000_20240322.txt";
FILE *in, *out;
__uint8_t ch;
printf("read file %s\n",instring);
__uint8_t buf[BUF_LENGTH];
int in_fd=open(instring,O_RDONLY);
int out_fd=open(outstring,O_RDWR|O_CREAT,0666);
if(in_fd==-1)
{
printf("read file fail\n");
close(in_fd);
return -1;
}
else{
printf("read file success\n");
read(in_fd,buf,BUF_LENGTH);
close(in_fd);
}
in = fopen(instring, "r");
out = fopen(outstring, "w");
int i=0;
while (fscanf(in, "%c", &ch) != EOF) {
if((i%16==0)&&(i>0)) // 这个16代表每行16个字节
{
fprintf(out,"\r\n");
}
i++;
fprintf(out, "%02X ", ch);
if(i>BUF_LENGTH)
break;
}
fclose(in);
fclose(out);
return 0;
}
分割后如下图: