【发布时间】:2012-10-13 15:53:55
【问题描述】:
可能重复:
Why do I get a segmentation fault when writing to a string?
如果我有一个指针并且我知道两个字符的索引,我将如何交换字符(我实际上并没有分配一个数组)
即
char *str = "hello" 我知道并且我想交换索引 0 和 4 的“h”和“o”,然后也返回指针。
我习惯了
temp = array[i];
array[i] = array[j];
array[j] = temp;
【问题讨论】:
-
不清楚你在问什么。