In a project in class I made a small piece of code that creates the file name depending on the date and time.
1 2 3 4
|
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%y-%m-%d %H+%M+%S.txt",timeinfo);
dateTime = buffer;
cout << "\n\n>>Saved to: " << dateTime << endl;
|
1 2 3
|
FILE * pFile;
pFile = fopen (dateTime.c_str(),"w");
if (pFile!=NULL)
|
never got an error with it.
only difference is that the last two pieces of code were made in c++ 2005, the code in the first post was made in c++ 2008
thanks for the catch on the >=, I haven't got the program to work with this piece of code, so that is one of the main reasons I didn't notice it. But I did this morning when I took my computer out of hibernate and the code was looking at me.
edit:
I replaced the strftime with sscanf_s in both locations and the error went away. I got 1 succeed so I ran the program, now I got an issue with the line of code:
1 2
|
temp = registration[x].day + dash + monthJAN + dash + registration[x].year;
string::traits_type::copy( date1, temp.c_str(), temp.length() +1 ); //Error here, read below.
|
Error when running the program:
Unhandled exception at 0x60abee64 in Serial Sorter.exe: 0xC0000005: Access violation writing location 0x0041d8b8.
I don't think this would help you guys any stating the error.
Each part in the temp line area all string variables, then in the second line, I was trying to convert the string temp to date1 which is "char *date1"
edit2:
I now have that line of code working by replacing:
|
string::traits_type::copy( date1, temp.c_str(), temp.length() +1 );
|
with
1 2
|
date1 = (char*)malloc( sizeof( char ) *(temp.length() +1) );
strcpy( date1, temp.c_str() );
|
The program runs up until it hits the line in time_t to_seconds:
|
p=(char *)sscanf_s(date,"%d-%b-%Y",&storage);
|
I get the Debug Assertion Failed message.