#include <stdio.h>
#include <stdlib.h>
void write_file(FILE *fp, unsigned char *arr, int len)
{
int i = 0;
for(i = 0 ; i < len; i+=2)
{
fprintf(fp,"0x%x,\n", arr[i]);
}
}
void read_file(FILE *fp, unsigned char* arr, int len)
{
int i = 0;
for (i = 0; i < len; i++)
{
fscanf(fp, "%c", arr+i);
}
}
int main(void)
{
FILE *fp1, *fp2;
unsigned char *arr;
arr = (unsigned char *)malloc(4096);
fp1=fopen("test.txt", "rb");
fp2=fopen("out.txt","a+");
read_file(fp1, arr, 4096);
write_file(fp2, arr, 4096);
fclose(fp1);
fclose(fp2);
free(arr);
return 0;
}
fopen读写文件
最新推荐文章于 2024-06-17 05:15:00 发布