#include <stdio.h>
#include <string.h>
#include <stdlib.h>//free
//D:\GBN\STM32F412RE\MDK-ARM\STM32F412RE\STM32F412REapp.hex
//D:\GBN\STM32F412RE\MDK-ARM\STM32F412RE\STM32F412REapp.bin
#define uint32_t unsigned int
int main(int argc,char **argv)
{
FILE *fp1,*fp2;
unsigned int lSize=0;
char *name = NULL;
unsigned char ch;
if(argc==1)
{
name = (char *)"GKOSON.hex";
printf("NEWNAME %s\r\n",name);
}
else if(argc==2)
{
name = argv[1];
printf("NEWNAME %s\r\n",name);
}
fp1 = fopen("STM32F412REapp.hex", "r");
if (NULL == fp1){ printf("NULL == fp1"); return 1;}
fp2 = fopen(name, "w");
if (NULL == fp2){ printf("NULL == fp2");return 1;}
#if 0 //不行!!
ch = fgetc(fp1);
while(ch!=EOF)
{
fputc(ch , fp2);
ch = fgetc(fp1);
}
#else
while(1)
{
ch = fgetc(fp1);
if(feof(fp1)) //如果读到了文件结尾,就退出 while循环
break;
fputc(ch , fp2);
}
#endif
fclose(fp1);
fclose(fp2);
free(fp1);
free(fp2);
printf("******GKOSON FINISHED*******");
return 1;
}
再文件夹 exe 可以看到HEX复制了