Combining large batches of .bin files with C language
Let me share with you a code for synthesizing bin files (I used it to make 0.96-inch OLED playback animation)
The buffer array changes itself according to the number of bytes in the file
#include<stdio.h>
#include<stdlib.h>
#define PICTURE_NUM 1314
int main(void)
{
int i = 0;
char buffer[1024] = {
0 };
char path[32] = "F:\\batch\\0000.bin";
FILE *fp1 = NULL, *fp2 = NULL;
fp2 = fopen("F:\\cai.bin", "wb");
if(fp2 == NULL)
{
fprintf(stderr, "Error!");
exit(EXIT_FAILURE);
}
for( i = 0 ; i < PICTURE_NUM ; i++) //连续复制粘贴
{
path[9] = i / 1000 + '0'; //为0000的最高位
path[10] = (i / 100) % 10 + '0';
path[11] = (i / 10) % 10 + '0';
path[12] = i % 10 + '0';
fp1 = fopen(path, "rb");
if(NULL == fp1)
{
fprintf(stderr, "Error Open %s\n", path);
exit(EXIT_FAILURE);
}
if(i % 100 == 0)
printf("%d\n", i);
fread(buffer, 1, 1024, fp1); //读取bin文件数据,相当于复制内容
fwrite(buffer, 1, 1024, fp2); //写入bin文件数据,相当于粘贴内容
fclose(fp1);
}
fclose(fp2);
return 0;
}