mktime()返回-1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>
#include "sys\stat.h"
#include "memory.h"
#include <conio.h>
typedef struct date
{
int dwYear;
int dwMonth;
int dwDay;
int dwHour;
int dwMin;
int dwSec;
} tDate;
void main()
{
char aszFileName[50];
struct stat FileInfo;
struct tm TempTime;
struct tm* pTempTime;
tDate date;
time_t dwFileTime;
time_t dwTempTime;
char aszBufTime[65];
memset(&TempTime,0,sizeof(tm));
FILE *fpFileList,*fpFileTime,*fpReport;
if((fpFileList=fopen("c:\\FileList.txt","r"))==NULL)
{
printf("打开文件名称列表失败!");
}
if((access("c:\\FileTime.txt",0))==-1)
{
if((fpFileTime=fopen("c:\\FileTime.txt","w"))==NULL)
{
printf("打开文件信息列表失败!");
}
while(!feof(fpFileList))
{
fscanf(fpFileList,"%s",aszFileName);
printf("%s\n",aszFileName);
stat(aszFileName,&FileInfo);
printf("%d\n",FileInfo.st_mtime);
fprintf(fpFileTime,"%d ",FileInfo.st_mtime);
}
fclose(fpFileTime);
}
else
{
rewind(fpFileList);
if((fpFileTime=fopen("c:\\FileTime.txt","r"))==NULL)
{
printf("打开文件信息列表失败!");
}
if((fpReport=fopen("c:\\Report.txt","w"))==NULL)
{
printf("打开输出报告文件失败!");
}
printf("输入时间基准: ");
scanf("%d-%d-%d %d:%d:%d",&date.dwYear,&date.dwMonth,&date.dwDay,&date.dwHour,&date.dwMin,&date.dwSec);
TempTime.tm_year=date.dwYear-1990;
TempTime.tm_mon=date.dwMonth-1;
TempTime.tm_mday=date.dwDay;
TempTime.tm_hour=date.dwHour;
TempTime.tm_min=date.dwMin;
TempTime.tm_sec=date.dwSec;
TempTime.tm_isdst=0;
printf("%d-%d-%d %d:%d:%d\n",TempTime.tm_year,TempTime.tm_mon,TempTime.tm_mday,TempTime.tm_hour,TempTime.tm_min,TempTime.tm_sec);
dwTempTime=mktime(&TempTime);
printf("%d\n",dwTempTime);
while((!feof(fpFileList))&&(!feof(fpFileTime)))
{
fscanf(fpFileList,"%s",aszFileName);
stat(aszFileName,&FileInfo);
fscanf(fpFileTime,"%d",&dwFileTime);
if(dwFileTime!=FileInfo.st_mtime)
{
pTempTime=localtime(&FileInfo.st_mtime);
sprintf(aszBufTime,"%04d-%02d-%02d %02d:%02d:%02d",pTempTime->tm_year+1900,pTempTime->tm_mon+1,pTempTime->tm_mday,pTempTime->tm_hour,pTempTime->tm_min,pTempTime->tm_sec);
fprintf(fpReport,"%s %s\n",aszFileName,aszBufTime);
}
}
fclose(fpFileTime);
fclose(fpReport);
}
fclose(fpFileList);
system("pause");
}