Hello coding community,
The code below is a variation on the run-length encoding but adapted for my hex string. The code is supposed to take the string and put a space between every two characters eg "3030" becomes "30 30" and puts the output of that into bytes vector and from that into the array. Now, it will place an array element into the temphexholder array and check if the next array element of databytes is the same as the element in temphexholder it will increment counter if not it will append counter and databytes to runlengthengthcoding string. So the result is eg. : original string: "303030304040" becomes "30044002". However when I try to use the function it gives me the error in the title
Code:
string integerrunlengthencoding(string hextext) {
//string hextext = "";
int counter,a;
unsigned char temphexholder[1];
cout << hextext ;
int length = hextext.size();
string output = "";
string runlengthengthcoding = "";
//for each block of 2 characters
for(int i =0 ; i< length; i=i+2)
{
//copy 2 characters and a space to the output
output += hextext.substr(i, 2) + " ";
}
std::istringstream hex_chars_stream(output);
std::vector<unsigned char> bytes;
unsigned int c;
unsigned char databytes[52]; // 52 data bytes
while (hex_chars_stream >> std::hex >> c)
{
bytes.push_back(c);
}
for(int q=0;q<52;q++){
databytes[q] = bytes[q];
}
for(int w=0;w<52;w++){
if(temphexholder[0] == databytes[w]){
counter++;
}
if(temphexholder[0] != databytes[w]){
runlengthengthcoding += databytes[w] + counter;
counter = 0;
temphexholder[0] = databytes[w];
}
}
return runlengthengthcoding;
}
int main (){
string teee = "303040505050efef30454540404040405050502021212123232345562929293445232334458939414123232323232323456789";
cout << teee;
cout << "The compressed string becomes: " << integerrunlengthencoding(string teee);
} // why is this not working