/////////////////////////////////////////////////////////////// // Application: Time/Date Logger // Author: Markus Diersbock // Created: 2001/08/13 // Description: Useful in batch files like autoexec.bat et al // to keep a log of Time/Date events. // Rights: Freeware /////////////////////////////////////////////////////////////// #include "stdafx.h" #include #include int main(int argc, char* argv[]) { FILE *logfile; time_t curtime; tm *tmhold; char tmbuf[50]; char logevent[255]; int argnum; if ( (logfile = fopen("c:\\LogFiles\\logins.log","a+")) == NULL) { printf("Error opening Log File!\n"); return 1; } else { time(&curtime); tmhold = localtime(&curtime); strftime(tmbuf, 49, "%Y/%m/%d %H:%M:%S", tmhold); strcpy(logevent, tmbuf); strcat(logevent,"\t"); strcat(logevent,argv[0]); if (argc > 1) { argnum = 1; while (argnum != argc) { strcat(logevent, " "); strcat(logevent, argv[argnum]); argnum++; } } strcat(logevent,"\n"); fputs(logevent, logfile); } if (fclose(logfile)) { printf("Error closing Log File!\n"); return 1; } return 0; }