Swap function for a char*
Posted
by Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2010-04-22T04:23:35Z
Indexed on
2010/04/22
4:33 UTC
Read the original article
Hit count: 129
I have the simple function below which swap two characters of an array of characters (s). However, I am getting a "Unhandled exception at 0x01151cd7 in Bla.exe: 0xC0000005: Access violation writing location 0x011557a4." error. The two indexes (left and right) are within the limit of the array. What am I doing wrong?
void swap(char* s, int left, int right) {
char tmp = s[left];
s[left] = s[right];
s[right] = tmp;
}
swap("ABC", 0, 1);
I am using VS2010 with unmanaged C/C++. Thanks!
© Stack Overflow or respective owner