ulBufWrite += ulThisWrite;
} while (ulBufRead -= ulThisWrite);
}
::fclose(fsrc);
::fclose(fdst);
return true;
}
fopen、fclose函数应该不会有问题。问题应该出在关键的fread与fwrite函数上。查看fread与fwrite的说明文档,如下:
SYNOPSIS
#include
size_t fread(void *ptr, size_t size, size_t nitems, FILE
*stream);
size_t fwrite(const void *ptr, size_t size, size_t nitems,
FILE *stream);
DESCRIPTION
The fread() function reads into an array pointed to by ptr
up to nitems items of data from stream, where an item of
data is a sequence of bytes (not necessarily terminated by a
null byte) of length size. It stops reading bytes if an
end-of-file or error condition is encountered while reading
stream, or if nitems items have been read. It increments the
data pointer in stream to point to the byte following the
last byte read if there is one. It does not change the con-
tents of stream. It returns the number of items read.
The fwrite() function writes to the named output stream at
most nitems items of data from the array pointed to by ptr,
where an item of data is a sequence of bytes (not neces-
sarily terminated by a null byte) of length size. It stops
writing when it has written nitems items of data or if an
error condition is encountered on stream. It does not change
the contents of the array pointed to by ptr. It increments
the data pointer in stream by the number of bytes written
and returns the number of items written.
读出或写入的内容由两个参数决定,一个是元素大小,一个是元素个数,读出或写入的总字节数就是元素大小乘以元素个数的积,但是这两个函数的返回值,不是读出或写入的总字节数,而是读出或写入的元素个数。这就是复制发生错误的根本原因所在。
阅读(203) | 评论(0) | 转发(0) |