我有一个文件,如下所示(十六进制)。
1F 00 48 3A 18 00 00 00 53 00 70 00 6F 00 75 00
73 00 65 00 5F 00 61 00 7A 00 61 00 6D 00 00 00
我正在尝试从文件中读取二进制数据并将其作为文本输出。我目前的代码如下:
#include<stdlib.h>
#include<stdio.h>
#include<iostream.h>
int main()
{
FILE *pFile, *tempFile;
pFile = fopen("C:\\wab files\\Admin.wab", "rb");
if(pFile == NULL)
{
fputs("file error", stderr);
exit(1);
}
tempFile = fopen("C:\\myfile.text","wb");
if(tempFile == NULL)
{
fputs("file not open", stderr);
exit(2);
}
int Contact_Id, Id_Size, Data_Info=0;
fread(&Contact_Id, 1, 4, pFile);
fread(&Id_Size, 1, 4, pFile);
Data_Info = Id_Size;
char* Main_buffer = (char*)malloc(Data_Info*sizeof(Data_Info));
fread(Main_buffer, 1, Id_Size, pFile);
const wchar_t* src = (unsigned short *) Main_buffer;
wcstombs ((char*) Main_buffer, src, Data_Info );
fwrite(Main_buffer, 1, Data_Info, tempFile);
free(Main_buffer);
return 0;
}
输出文本文件包含以下内容:
Spouse_azam _ a z a m
为什么_ a z a m
显示在文本文件中?我只想写Spouse_azam
。