這是我第一次問這裏。 我只是想知道這段代碼的「返回」是否正確,特別是第一個。返回指針C
tVideo* getVideo(int id, tTblVideo* table){
tVideo* videoFound = NULL;
int i;
for(i = 0; i < table->length; i++){
if(table->data[i]->mediaID == id) return *table->data[i];
}
return videoFound;
}
編輯:添加tTblVideo定義:
typedef struct {
/* Number of stored files */
int length;
/* Array of video files */
tVideo *data;
} tTblVideo;
沒有辦法知道沒有看到'tTblVideo'。它是否編譯? – jxh
第二個返回總是給出NULL,因爲什麼都沒有設置videoFound。也就是說,提前退出是要走的路,所以這不是一個真正的問題。這只是一個不必要的變量。 – ams
好的做法是用'videoFound = table-> data [i]'替換'return * table-> data [i]'。 –