This code is to convert from input string to binary. But the pointer tempPointer
in dataToCode()
function is crashing the application. Please guide. Thank you.
int main(void)
{
string text;
cout << " Enter the text/code you want to convert: ";
cin >> text;
dataToCode(text);
}
string* asciiToBinary(string input) {
string binaryArray[5];
for (int i = 0; i < input.length(); i++) {
binaryArray[i] = bitset<8>(input[i]).to_string();
//cout << binaryArray[i] << endl;
}
string* tempPointer = binaryArray;
for (int i = 0; i < input.length(); i++) {
//cout << *(tempPointer + i);
}
return tempPointer;
}
void dataToCode(string input) {
string binaryCode[5];
string* tempPointer = asciiToBinary(input);
for (int i = 0; i < input.length(); i++) {
//binaryCode[i] = *(tempPointer + i);
//cout << binaryCode[i] << endl;
cout << *(tempPointer + i);
}
}