I am trying to reverse a string,
No idea why am I getting this below error as Unhandled exception at 0x00f818c2 in CPP_TEST.exe: 0xC0000005: Access violation writing location 0x00f87838.
?
Please help me.
void swap(char* in, int start, int end)
{
char *temp = new char;
*temp = in[start];
in[start] = in[end];//Unhandled exception at 0x00f818c2 in CPP_TEST.exe: 0xC0000005: Access violation writing location 0x00f87838.
in[end] = *temp;
}
void Reverse(char* in, int start, int end)
{
if(start == end)
{
cout << in <<endl;
return;
}
else
{
while(start != end)
{
swap(in, start++, end--);
//Reverse(in, start, end);
}
}
}
int main()
{
char* in = "Hello";
Reverse(in, 0, 4);
system("pause");
return 0;
}