Good day, Please can someone assist? I am trying to reverse a member that is a pointer array.
string::string(char *c)
{
int i =0;
while ((c[i] != '\0'))
{
i++;
}
_lenght= i;
_aString=*&c;
}
void string::reverse() //Requirements specify to have this argument
{
for(int i=0; i<_lenght/2; i++)
{
std::swap(_aString[i], _aString[_lenght-i-1]);
}
}
I get a runtime error on this.
This is my main function
int main(){
string a;
std::cout << "a is " << a << "\n";
string b("12345");
string c("12345",3);
std::cout << "c is " << c << "\n";
c = a;
a = b;
std::cout << "a is " << a << "\n";
b.reverse();
std::cout << "a is " << a << "\n";
return 0;
}
Error I'm getting is
Unhandled exception at 0x00fd6710 in UnisaLesson1.exe: 0xC0000005: Access violation writing location 0x00fdfd08.
Sorry, I'm still a newb.