建立自己的BIN file ( 懶惰不解釋原理)

今天沒精神解釋,先Po程式碼上來,以後再解釋我想要作的事


此程式目前會看到的功能是, 輸入 一串字串,動態的存入二進位檔

主要的目標是當作 自己寫option rom的前哨戰


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void ShowHelp(void);
void main(int argc, char* argv[])
{
   if (argc != 3) { ShowHelp();}
   else{
   FILE* fptr;
   fptr=fopen(argv[1],"r");
// if file did not exist , create it
   if (fptr==NULL) { fptr = fopen(argv[1],"w"); fclose(fptr);}
// enable file writable
   fptr=fopen(argv[1],"w");
   char* buffer;
// open memory allocate function

   int buffer_size=0;
   buffer_size = strlen(argv[2]);
   buffer = (char* )malloc(buffer_size);
   strcpy(buffer,argv[2]);
   fwrite(buffer,1,buffer_size,fptr);
// free the memory allocate spaces
   free(buffer);
   fclose(fptr);
   }
}
void ShowHelp(void){
     printf("Invalid Command!\n");
     printf("Only 2 argument should be execute!\n");
     printf("DINDISP 1.bin string(ASDFG....)\n");
}

留言

這個網誌中的熱門文章

如何在VS2022 Community 簡要的設定UDK2018的環境

自製讀取 H 檔案並找出 define 的程式

如何Build UDK2018