# include & ltstring.h & gt
# include & ltstdio.h & gt
# include & ltdirent.h & gt
# include & lttime.h & gt
#定義日誌文件"。/目錄日誌0 "
int g _ Count
//#定義MAXLEN?1024
void WriteDebugLog(char * str);
int main(int argc,char **argv)
{
char str[1024]= { 0 };
strcpy(str,“找不到文件”);
int i=0,j = 0;
for(I = 0;我& lt10;i++)
{
for(j = 0;j & lt50;j++)
{
WriteDebugLog(str);
}
}
返回0;
}
void WriteDebugLog(char *str)
{
char buf[2048]= { 0 };
char log filename[50]= { 0 };
//long MAXLEN = 50 * 1024 * 1024;//50MB
int iMax = 1024;//1K
time_t時間;
FILE * fp = NULL
struct TM * p;
時間(& amptimep);
p = localtime。timep);
memset(buf,0,sizeof(buf));
sprintf(buf,"[% d-% d-% d % d:% d:% d][調試]",(1900+p-& gt;tm_year),(1+p->;tm_mon),p-& gt;tm_mday,p-& gt;tm_hour,p-& gt;tm_min,p-& gt;TM _ sec);//周p-& gt;tm_wday
strcat(buf,str);
strcat(buf," \ r \ n ");
strcpy(日誌文件名,日誌文件);
int len = strlen(log filename);
log filename[len-1]= ' 0 '+g _ Count;
fp = fopen(logFileName," r ");
if(fp==NULL)
{
fp = fopen(logFileName," w+");
}
其他
{
fseek(fp,0,2);//SEEK_END值為2。
if( ftell(fp)>= iMax)
{
fclose(FP);
if(g _ Count & gt;= 9)?
{
log filename[len-1]= ' 0 ';
g _ Count = 0;
}
其他
{
g _ count++;
log filename[len-1]= ' 0 '+g _ Count;
//?printf("\n%c ",' 0 '+g _ Count);
}
fp = fopen(logFileName," w+");
}
其他
{?
fclose(FP);
fp = fopen(logFileName," a ");
}
}
fwrite(buf,1,strlen(buf),FP);
fclose(FP);
}