#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <Windows.h>
#include <sys/stat.h>
#define MAX_FILE_LENGTH (500*1024*1024)
__int64 getFileSize(FILE* file) {
struct _stat64 st;
if (_fstat64(_fileno(file), &st) == 0)
return st.st_size;
return -1;
}
int main()
{
FILE* file = fopen("D:\\frame.log", "r");
if (file == NULL) {
printf("open file failed");
return 0;
}
__int64 size = getFileSize(file);
printf("file size:%lld Bytes\n", size);
char strFileName[1024];
int length = 0;
char buf[1024];
int ret = 0;
int order = 0;
FILE* pOutFile = NULL;
int tempLength = 0;
while (!feof(file)) {
ret = fread(buf, 1, 1024, file);
if (ret > 0) {
if (!pOutFile) {
order++;
sprintf(strFileName, "D:\\frame\\%d.log", order);
pOutFile = fopen(strFileName, "w+");
tempLength = 0;
printf("write the file name is %s\n", strFileName);
}
if (pOutFile) {
fwrite(buf, 1, ret, pOutFile);
} else {
printf("meet an error when write file\n");
}
tempLength += ret;
if (tempLength >= MAX_FILE_LENGTH) {
fclose(pOutFile);
pOutFile = NULL;
}
}
}
fclose(file);
return 0;
}