00 FF FF FF FF FF FF 00 4C 2D 1B 0D 45 4D 5A 5A
29 1A 01 03 0E 30 1B 78 2A 4A 05 A2 5A 52 A1 27
0D 50 54 BF EF 80 71 4F 81 C0 81 00 81 80 95 00
A9 C0 B3 00 01 01 02 3A 80 18 71 38 2D 40 58 2C
45 00 DD 0C 11 00 00 1E 00 00 00 FD 00 38 4B 1E
51 11 00 0A 20 20 20 20 20 20 00 00 00 FC 00 53
32 32 46 33 35 30 0A 20 20 20 20 20 00 00 00 FF
00 48 34 5A 48 41 30 30 30 39 36 0A 20 20 01 EB
我想把txt內容轉換成*.bin file
1. 開發環境 : DEV C++
2. 程式碼
#include <stdio.h> #include <stdlib.h> #include <string.h> size_t ReadTxtFile(FILE *inf, unsigned char *dest, FILE *outfile) { size_t count = 0; int n; unsigned char OneByte; if (dest == NULL) { //讀取txt檔案內容,轉成16進制.直到讀取結束 while ((n = fscanf(inf, "%hhx", &OneByte)) == 1 ) { //printf("@@ %x\n",OneByte); //把讀取出來的資料寫入bin檔 fwrite(&OneByte, sizeof(unsigned char), 1, outfile); count++; } } if (n != EOF) { ; // handle syntax error } //printf("count=%d\n",count); return count; } int main() { //讀取txt檔案,檔案一定要放在跟目錄下不然會找不到 FILE *FileIn = fopen("d:\\21.txt", "rt"); //如果檔案為空return fail if (!FileIn) { fclose(FileIn); return -1; } //創建一個bin檔 FILE* FileOut = fopen("d:\\fileOut.bin","wb+"); //如果檔案為空return fail if (!FileOut) { fclose(FileOut); return -1; } //轉換檔案 size_t n = ReadTxtFile(FileIn, NULL, FileOut); //把指標指向檔案頭 rewind(FileIn); //關閉檔案 fclose(FileIn); fclose(FileOut); system("PAUSE"); return 0; }
請問有讀取bin檔案內容輸出txt file的嗎?
回覆刪除作者已經移除這則留言。
回覆刪除