[ad_1]
I have a program that reverses some bytes from the end of a char array, and then tries to write them to file. I am opening the file in binary mode already, but whenever it gets to writing 0x00, it writes 0x20 instead. Take a look:
#include "stdafx.h"
#include <fstream>
#include <iostream>
void ReverseArr(char* arr, int start, int end)
int temp;
if (start >= end)
return;
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
ReverseArr(arr, start + 1, end - 1);
void WriteEnd(char* data, int len)
std::ofstream file;
file.open("test.bin", std::fstream::out
int main()
char data[77] = 0x27,0xCC,0x00,0x01,0x00,0x00,0x10,0xB9,0x12,0x12,0x53,0xBE,0x06,0x00,0x01,0x04,0x00,0x00,0x00,0x41,0x00,0x00,0x00,0x08,0xF3,0x02,0x01,0x00,0x06,0x00,0x69,0x02,0x06,0x26,0xA8,0x01,0x79,0x00,0x02,0x66,0xC1,0xF9,0x56,0x86,0x41,0x6A,0x73,0x38,0x02,0x66,0x43,0x28,0x85,0xF8,0x03,0x79,0x00,0x02,0x66,0xC1,0xF5,0xDC,0x2A,0x41,0x48,0x30,0x6A,0x04,0x66,0x40,0xD7,0x0A,0x3E,0xFD,0x6B,0x00,0x11 ;
WriteEnd(data, 77);
return 0;
My program is supposed to take the last 50 (77 - 27) bytes of this array, reverse them (which it does), and then write the reversed output to test.bin. But this is the output in test.bin:
11 20 6B FD 3E 0A D7 40 66 04 6A 30 48 41 2A DC F5 C1 66 02 20 79 03 F8 26 28 43 66 02 38 73 6A 41 20 56 F9 C1 66 02 20 79 01 A8 26 06 02 69 20 06 20
It seems like other than the fact every 0x00 was replaced with 0x20, the output is correct. Why is every 0x00 replaced by 0x20, and how can I fix that?
[ad_2]
لینک منبع