为什么这个字符串反转C代码会导致分段错误?
#include <string.h>void reverse(char *s);int main() { char* s = "teststring"; reverse(s); return 0;}void reverse(char *s) { int i, j; char temp; for (i=0,j = (strlen(s)-1); i < j; i++, j--) { temp = *(s+i); //line 1 *(s+i) = *(s+j); //line 2 *(s+j) = temp; //line 3 }}
更新
陪伴而非守候
森栏