[問題] qsort
開發平台(Platform): (Ex: Win10, Linux, ...)
Win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Dev c
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
要針對特定的row或col排序 結果有些數字被改成0
餵入的資料(Input):
一個txt檔 內含100個double 元素
已在code中存成10*10的arr
預期的正確結果(Expected Output):
針對特定的row或 col做排序
錯誤結果(Wrong Output):
https://i.imgur.com/p63WQXu.jpg

紅色框起來處 不知為何變成0
雖然是有達到針對特定的row/col排序 可是部分數字被改成0
如果將3-5行註解掉 只針對row做排序是沒問題的
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
printf("-----Before sort-----\n");
print(arr);
printf("-----After sort 7th column-----\n");
qsort(&arr[0][7],10,sizeof (arr[0]),cmp);
print(arr);
printf("-----After sort 3rd row------\n");
qsort((void*)&arr[3][0],10,sizeof (double),cmp);
print(arr);
int cmp( const void *a , const void *b ){
return *(double *)a > *(double *)b ? 1 : -1;
}
補充說明(Supplement):
我有嘗試著修改第四行qsort中的sizeof (arr[0]) 改成 sizeof(double) 但是就無法對c
olumn 排序
問題應該是出在這個地方 該如何修改比較好? 感謝各位
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.52.173.41
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1544339502.A.6E6.html
※ 編輯: achicn3 (27.52.173.41), 12/09/2018 15:16:19
→
12/09 15:44,
7年前
, 1F
12/09 15:44, 1F
→
12/09 15:44,
7年前
, 2F
12/09 15:44, 2F
原來如此 感謝~
※ 編輯: achicn3 (27.52.173.41), 12/09/2018 16:45:58
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章