/* 文件操作 要求:将文件 in.exe 复制为名为 out.exe文件 请在int main()函数里面编辑 */ #include <stdio.h> #include <stdlib.h> #include <string.h> int filesize(FILE *stream); void BinaryFileCopy(const char * src_file_name, const char * dst_file_name); int main() { char *src_file_name = "Unnamed.gif"; char *dst_file_name = "Unnamed2.gif"; BinaryFileCopy(src_file_name, dst_file_name); return 0; } void BinaryFileCopy(const char * src_file_name, const char * dst_file_name) { const int kBufSize = 1024; char buf[kBufSize]; FILE *src_fp = fopen(src_file_name, "rb"); if (src_fp == NULL) { printf("src file open error/n"); exit(1); } FILE *dst_fp = fopen(dst_file_name, "wb+"); if (dst_fp == NULL) { printf("dst file open error/n"); exit(1); } int n; while (!feof(src_fp) && (n=fread(buf, 1, kBufSize, src_fp)) > 0) { fwrite(buf, 1, n, dst_fp); } fclose(src_fp); fclose(dst_fp); } int filesize(FILE *stream) { int curpos, length; curpos = ftell(stream); fseek(stream, 0L, SEEK_END); length = ftell(stream); fseek(stream, curpos, SEEK_SET); return length; }