这是我的代码:
void reverseStr(char *str)
{
if (str == NULL) return;
int i=0, j=strlen(str) -1;
while(i<j)
{
char temp = str[j]; //i think this is the cause of the problem
str[j] = str[i];
str[i] = temp;
i++;
j--;
}
}
所以这里叫它:
int main()
{
char *str = "Forest Gump";
reverseStr(str);
cout << str;
}
这是我的错误:
/Applications/TextMate.app/Contents/SharedSupport/Bundles/C.tmbundle/Support/bin/bootstrap.sh:第 7 行:1931 总线错误“$3”.out
有什么想法吗?提前致谢。