本帖最后由 toofree 于 2020-2-27 12:53 编辑
编译时设置不了,在链接完成后才能知道程序总共使用了哪些空间,占用空间有可能是不连续的。
但是生成HEX或BIN后,程序空间分配就固定下来了。
如果是用BIN的文件尾的确是程序占用空间的尾部的话,可以写个C代码,编辑BIN文件,在文件尾追加写入你要添加的"this is the end of bin."
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- char name[256];
- char *p="this is the end of bin.";
- char *pstr;
- int nReturn,StrCount=0;
- int NameSize=0;
- FILE *fp_src,*fp_dst;
- printf("Hello world!\n");
- printf("请输入要操作的文件名:\n");
- NameSize = scanf("%[^\n]",name);
- printf("\n%s\n",name);
- fp_src = fopen(name,"rb");
- if (fp_src == NULL)
- {
- printf(""%s" file is not exist !\n\r",name);
- return 1;
- }
- fclose(fp_src);
- fp_src = fopen(name,"ab+");
- if (fp_src == NULL)
- {
- printf(""a.bin" file is not exist !\n\r");
- return 1;
- }
- fseek(fp_src,0,SEEK_END);
- fputs(p, fp_src);
- fclose(fp_src);
- return 0;
- }
file_BinAddStr.rar
(2.42 KB, 下载次数: 13)
|