I have this function that receives a string of “chars”. I’m trying to go through that string and use pointers to see if the second element is the same as the first. SO lets say I have aaabbccddd, i would want to write into an array that i have 3a, 2 bs, 2cs and 3ds. I’m really struggling in figuring out if the second string is the same as the first by using pointers. I created this temp pointer and i do temp++. THis essentially just shows everything after the second term and so on…How can i individually look at the second term and compare it to the first term with just pointers.
void RLE<T>::Compress(const T* input, int inSize)
{
delete m_Data;
m_Size = 0;
T * m_Data;
m_Data = new T[inSize*2];
int runSize = MaxRunSize();
const T * temp;
temp = input;
temp++;
This part right here always gives me errors and it says that I have a Bad pointer. I understand that this essentially doesn’t work because my input pointer is longer than the temp pointer i created. and my array never gets initialized
if (temp == input)
{
std::cout<<"here"<<std::endl;
int number = 1;
number++;
m_Data[0] = number;
m_Size++;
std::cout<<temp;
m_Data[m_Size] = *temp;
}
}
Any help would be much appreciated
Is your error right at the start?
This wouldn’t work since
m_Datais undefined at that point, unless, going by the naming, that is a member as well, in which case you should not redefine it.Shouldnt you do
instead of