写一个复制文件的小程序,愣是没想明白这两种写法有什么区别,我还以为我几年前就明白了呢。
copy = fread (buf, 1, sizeof (buf), in); fwrite (buf, 1, copy, out);
copy = fread (buf, sizeof (buf), 1, in); fwrite (buf, copy, 1, out);
傻乎乎的想了很久,突然明白了,返回值!!
fread的原型是
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
返回的是复制了多少个 nmemb……