[英]Convert a file into binary buffer in C?
我只是從C / C ++開始。 我可以從二進制文件中寫入文件:
FILE *myFile= fopen("/mnt/music.mp3", "ab+"); // Doesn't exist
fwrite(binaryBuffer, sizeOfBuffer, 1, myFile);
我只想從“ myFile”中獲取一個新的“ binaryBuffer”
我該怎么做?
謝謝 !
使用fread
函數,其功能類似於fwrite
:
char buffer[BUFFER_SIZE]; // declare a buffer
fread(buffer, length, 1, file); //read length amount of bytes into buffer
如果您不知道要讀取多少個字節,可以搜索文件末尾以找到長度。
(如果您從剛寫入的文件中讀取內容,則將要倒帶) http://www.cplusplus.com/reference/cstdio/fread/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.