我試圖做一個簡單的函數,爲一個值的第一個實例搜索一個選定的列,然後讓它返回它所在的行。這將搜索一個名爲「SPREADSHEET」 。但是,我遇到一些重大問題。指針比較造成的錯誤
我收到錯誤「memcpy的參數1的不兼容類型」以及其他一些錯誤。這裏是我的代碼:
// Searches down the specified column for a row which contains text.
// The search starts at row number rowNum;
// The result is the row number (where the first row is numbered 0).
// If the text is not found, the result is -1.
int SS_FindRow(SPREADSHEET *ss, int colNum, char *text, int startNum) {
if (debug)
fprintf(stderr, "DEBUG: Call to SS_FindRow(--,%d,%s,%d)\n",
colNum, text, startNum);
// TO BE COMPLETED!
SPREADSHEET read;
memcpy(read,ss,sizeof(ss));
int i;
for(i = startNum; i < MAXROWS; i++) {
if(strcmp(&read.contents[i][colNum],text)==0)
return i;
}
return -1;
}
我真的難住,可能是什麼原因造成這種情況。運行程序,無論我的輸入是if語句,都不會成功。幫幫我?的memcpy的
嘗試'memcpy(&read,ss,sizeof(* ss));' – BLUEPIXY 2014-09-24 11:14:51
「memcpy的參數1的不兼容類型」表示它應該是memcpy(&read,ss,sizeof(ss))'。那麼其他錯誤呢? – starrify 2014-09-24 11:14:55
@starrify:'sizeof * ss'。 – Deduplicator 2014-09-24 11:15:26