Possible Duplicate:
Why do I get a segmentation fault when writing to a string?
I have the following program:
#include <iostream>
using namespace std;
void reverseString(char* first, char* last)
{
while(first < last)
{
cout << *first << " " << *last << endl; //for debugging; prints 'H' and 'o' then crashes
char temp = *last;
*last = *first; //this line crashes the program
*first = temp;
first++;
last--;
}
}
int main()
{
char* s = "Hello";
reverseString(s, s + strlen(s) - 1);
cout << s << endl;
}
However, I'm having trouble swapping the values to which the pointers point. I thought *p = *p1 should just set the pointed-to value of p to the pointed-to value of p1, but something seems bugged up. Thanks in advance for any help!