比方说,我有一个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