我写了这个基本功能:
int save_files(PCHAR fileName)
{
errno_t err;
FILE* pFile = NULL;
do
{
if (!fileName)
{
printf("Input is NULL \n");
break;
}
err = fopen_s( &pFile, fileName, "r");
if(0 != err)
{
printf("The file %s was not opened for reading\n", fileName);
}
else
{
printf("The file %s was opened for reading \n", fileName);
}
/*getting the fileSize */
fileSize = dbg_getFileSize(pFile);
printf("############# FILE SIZE IS : %d #############\n" );
}
这是获取文件大小的函数:
UINT32 dbg_getFileSize(FILE *file)
{
UINT32 size = 0 ;
if (file == NULL)
{
return -1;
}
fseek(file , 0L , SEEK_END);
size = ftell(file);
fseek(file, 0L, SEEK_SET);/*set it to the head!!! */
return size;
}
我一直打开相同的路径,每次尝试用“r”和“rb”打开它时都会得到不同的大小,但仍然得到相同的不同数字..