I'm trying to write a function to create a log file that includes the current system time in the file name. When I run this code, I have an error code of "invalid argument" for fopen. When I try to print the file name, its shows up correctly. Also, when I try to replace the system time with "123" the file creates fine. I appreciate any help.
Code:
void BuildLogFile(char *drive)
{
// Build path to log
char logFileName[100] ="";
char s[30];
size_t i;
struct tm tim;
time_t now;
now = time(NULL);
tim = *(localtime(&now));
i = strftime(s,30,"%m%d%I%M\n",&tim);
printf("%s", s);
strcpy(logFileName, drive);
strcat(logFileName, ":\\Test\\GrpClean_");
strcat(logFileName, s);
strcat(logFileName, ".log");
printf("%s",logFileName);
fpLogFile = fopen(logFileName,"w");
if (fpLogFile == NULL)
{
perror("Unable to open file");
}
}