RE: [Dev-C++] Time stamping an output file.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Benjamin W. <ben...@ho...> - 2002-02-28 14:06:27
|
<html><div style='background-color:'><DIV>
<P>Ioannis,</P>
<P>You didn't let me down man. Searching every crevace for an inefficiency. I like your style. I wasn't aware that strftime() was portable to UNIX, but after looking up the function I see that it is fully ANSI C compatible...so thank you for pointing out my misleading statement about the portability.</P>
<P>Secondly, this is just a "test" program...I specify the path in the actual production program because the program does not run in the directory where the output file is placed as is common with production environment directory structures. </P>
<P>You are right though, if you want the output file to go into the directory from where the *.exe is run from, then you do not need to provide a path.</P>
<P>Thanks for the analysis. Have a good day.<BR><BR><FONT face="Geneva, Arial, Sans-serif" size=2>Benjamin Wheeless<BR></FONT><FONT face="Geneva, Arial, Sans-serif" size=2><STRONG>Network Systems - Delta Airlines, Inc.<BR></STRONG></FONT><FONT face=Arial size=2><STRONG>Atlanta, GA - USA 30320<BR></STRONG></FONT><FONT face=Arial size=2><STRONG>==============================</STRONG></FONT></P></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>----Original Message Follows----
<DIV></DIV>From: "Ioannis Vranos" <NO...@YA...>
<DIV></DIV>To: "Dev-C++" <DEV...@LI...>
<DIV></DIV>Subject: RE: [Dev-C++] Time stamping an output file.
<DIV></DIV>Date: Thu, 28 Feb 2002 15:23:02 +0200
<DIV></DIV>
<DIV></DIV>-----Original Message-----
<DIV></DIV>From: dev...@li...
<DIV></DIV>[mailto:dev...@li...] On Behalf Of Benjamin
<DIV></DIV>Wheeless
<DIV></DIV>Sent: Thursday, February 28, 2002 3:05 PM
<DIV></DIV>To: dev...@li...
<DIV></DIV>Subject: RE: [Dev-C++] Time stamping an output file.
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>Morning,
<DIV></DIV>
<DIV></DIV>First of all, thanks again Ioannis and Jason for the suggestions.
<DIV></DIV>
<DIV></DIV>Secondly, I figured if anyone were interested, below is how I solved
<DIV></DIV>this time stamp problem. It is not portable to a Unix/Unix-based
<DIV></DIV>platform, but since the job on my end runs on an NT platform...it serves
<DIV></DIV>the purpose that I need it to serve.
<DIV></DIV>
<DIV></DIV>/*DATE STAMP TEST PROGRAM*/
<DIV></DIV>
<DIV></DIV>#include <STDIO.H>
<DIV></DIV>#include <STDLIB.H>
<DIV></DIV>#include <TIME.H>
<DIV></DIV>
<DIV></DIV>int main()
<DIV></DIV>{
<DIV></DIV>FILE* testfile ;
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>char* PtrToFname ;
<DIV></DIV>
<DIV></DIV>Not needed
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>char FileName[27] ;
<DIV></DIV>time_t CurTime ;
<DIV></DIV>struct tm* datetime ;
<DIV></DIV>
<DIV></DIV>CurTime = time( NULL ) ;
<DIV></DIV>datetime = localtime( &CurTime ) ;
<DIV></DIV>
<DIV></DIV>strftime( FileName, 27, "C:\\temp\\hsloan%Y%m%d.txt", datetime ) ;
<DIV></DIV>
<DIV></DIV>printf( "%s", FileName ) ;
<DIV></DIV>
<DIV></DIV>PtrToFname = FileName ;
<DIV></DIV>
<DIV></DIV>Not needed
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>testfile = fopen( PtrToFname, "w" ) ;
<DIV></DIV>if( testfile == NULL )
<DIV></DIV>{
<DIV></DIV>printf( "\nUNABLE TO CREATE OUTPUT FILE! (ABNORMAL TERMINATION)\n" )
<DIV></DIV>;
<DIV></DIV>exit( 0 ) ;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>fclose( testfile ) ;
<DIV></DIV>
<DIV></DIV>return 0 ;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>Thanks again everyone.
<DIV></DIV>
<DIV></DIV>Benjamin Wheeless
<DIV></DIV>Network Systems - Delta Airlines, Inc.
<DIV></DIV>Atlanta, GA - USA 30320
<DIV></DIV>==============================
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>So the program becomes:
<DIV></DIV>
<DIV></DIV>/*DATE STAMP TEST PROGRAM*/
<DIV></DIV>
<DIV></DIV>#include <STDIO.H>
<DIV></DIV>#include <STDLIB.H>
<DIV></DIV>#include <TIME.H>
<DIV></DIV>
<DIV></DIV>int main(void)
<DIV></DIV>{
<DIV></DIV>FILE* testfile ;
<DIV></DIV>char FileName[27] ;
<DIV></DIV>time_t CurTime ;
<DIV></DIV>struct tm* datetime ;
<DIV></DIV>
<DIV></DIV>CurTime = time( NULL ) ;
<DIV></DIV>datetime = localtime( &CurTime ) ;
<DIV></DIV>
<DIV></DIV>strftime( FileName, 27, "C:\\temp\\hsloan%Y%m%d.txt", datetime ) ;
<DIV></DIV>
<DIV></DIV>printf( "%s", FileName ) ;
<DIV></DIV>
<DIV></DIV>testfile = fopen( FileName, "w" ) ;
<DIV></DIV>if( testfile == NULL )
<DIV></DIV>{
<DIV></DIV>printf( "\nUNABLE TO CREATE OUTPUT FILE! (ABNORMAL TERMINATION)\n" )
<DIV></DIV>;
<DIV></DIV>exit( 0 ) ;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>fclose( testfile ) ;
<DIV></DIV>
<DIV></DIV>return 0 ;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>The program should be portable to UNIX too given that you provide the
<DIV></DIV>correct path syntax (/ for directories). Also why provide path anyway?
<DIV></DIV>(it will be created in the current path where the program is excuted).
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>Ioannis
<DIV></DIV>
<DIV></DIV>* Ioannis Vranos
<DIV></DIV>* Programming pages:
<DIV></DIV>http://www.noicys.d2g.com
<DIV></DIV>* Alternative URL: http://run.to/noicys
<DIV></DIV>
<DIV></DIV></div><br clear=all><hr>Join the worlds largest e-mail service with MSN Hotmail. <a href='http://go.msn.com/bql/hmtag4_etl_EN.asp'>Click Here</a><br></html>
|