代碼:`char ss[10][5] = {"worin", ...}` → 最長串長 5,但無 `\0` 空間,`strcpy` 越界寫入相鄰內存。
char ss[10][6] = {"worin", "trafi", "panda", "dalai", "lama2", "strin", "tende", "racof", "lenth", "recte"};
// 或動態分配
char** ss = malloc(10 * sizeof(char*));
for (int i=0; i<10; ++i) ss[i] = strdup(arr[i]);
void sort(char* p[], int n) { // 指針數組排序,不動數據
for (int i=0; i 0) {
char* tmp = p[j]; p[j] = p[j+1]; p[j+1] = tmp;
}
}
**核心教訓**:C 字符串**必須**以 `\0` 結尾,數組列數 ≥ `strlen(max) + 1`。