比方說,我有一個5000字節大小的文件,我試圖讀取它。在fread調用中元素的大小和數量是否可以交換?
我有這樣的代碼:
int main()
{
char *file_path[] = "/path/to/my/file"
FILE *fp= fopen(file_path,"rb"); //open the file
fseek(fp, 0, SEEK_END); // seek to end of file
unsigned long fullsize = ftell(fp); //get the file size (5000 for this example)
fseek(fp, 0, SEEK_SET); //bring back the stream to the begging
char *buf = (char*)malloc(5000);
fread(buf,5000,1,fp);
free(buf);
return 0;
}
我也可以代替fread
呼叫與
fread(buf,1000,5,fp);
什麼是好?爲什麼? 在優化問題上,我瞭解到返回值是不同的。
這兩段代碼做了不同的事情。你想達到什麼目的? – Nayuki
你的意思是'fread(buf,1000,5,fp)'和'fread(buf,5000,1,fp)'之間的區別嗎? – Downvoter
@cad是的。我試圖在buf中處理數據,並操縱他..一些memcpy,一些寫入另一個文件.. – raptor0102