RE: [Dev-C++] Time stamping an output file.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2002-02-28 13:24:46
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Benjamin
Wheeless
Sent: Thursday, February 28, 2002 3:05 PM
To: dev...@li...
Subject: RE: [Dev-C++] Time stamping an output file.
Morning,
First of all, thanks again Ioannis and Jason for the suggestions.
Secondly, I figured if anyone were interested, below is how I solved
this time stamp problem. It is not portable to a Unix/Unix-based
platform, but since the job on my end runs on an NT platform...it serves
the purpose that I need it to serve.
/*DATE STAMP TEST PROGRAM*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
FILE* testfile ;
char* PtrToFname ;
Not needed
char FileName[27] ;
time_t CurTime ;
struct tm* datetime ;
CurTime = time( NULL ) ;
datetime = localtime( &CurTime ) ;
strftime( FileName, 27, "C:\\temp\\hsloan%Y%m%d.txt", datetime ) ;
printf( "%s", FileName ) ;
PtrToFname = FileName ;
Not needed
testfile = fopen( PtrToFname, "w" ) ;
if( testfile == NULL )
{
printf( "\nUNABLE TO CREATE OUTPUT FILE! (ABNORMAL TERMINATION)\n" )
;
exit( 0 ) ;
}
fclose( testfile ) ;
return 0 ;
}
Thanks again everyone.
Benjamin Wheeless
Network Systems - Delta Airlines, Inc.
Atlanta, GA - USA 30320
==============================
So the program becomes:
/*DATE STAMP TEST PROGRAM*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
FILE* testfile ;
char FileName[27] ;
time_t CurTime ;
struct tm* datetime ;
CurTime = time( NULL ) ;
datetime = localtime( &CurTime ) ;
strftime( FileName, 27, "C:\\temp\\hsloan%Y%m%d.txt", datetime ) ;
printf( "%s", FileName ) ;
testfile = fopen( FileName, "w" ) ;
if( testfile == NULL )
{
printf( "\nUNABLE TO CREATE OUTPUT FILE! (ABNORMAL TERMINATION)\n" )
;
exit( 0 ) ;
}
fclose( testfile ) ;
return 0 ;
}
The program should be portable to UNIX too given that you provide the
correct path syntax (/ for directories). Also why provide path anyway?
(it will be created in the current path where the program is excuted).
Ioannis
* Ioannis Vranos
* Programming pages: <http://www.noicys.d2g.com/>
http://www.noicys.d2g.com
* Alternative URL: <http://run.to/noicys> http://run.to/noicys
|