Thread: 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-25 22:23:12
|
<html><div style='background-color:'><DIV>
<P>Thanks Gents (Ioannis & Jason). I appreciate the help on this one.</P>
<P>Have a good afternoon.</P></DIV>
<DIV></DIV>
<DIV><FONT face="Geneva, Arial, Sans-serif" size=2>Benjamin Wheeless</FONT></DIV>
<DIV></DIV>
<DIV><FONT face="Geneva, Arial, Sans-serif" size=2><STRONG>Network Systems - Delta Airlines, Inc.</STRONG></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><STRONG>Atlanta, GA - USA 30320</STRONG></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><STRONG>==============================</STRONG></FONT></DIV>
<DIV> </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: Mon, 25 Feb 2002 21:18:48 +0200
<DIV></DIV>
<DIV></DIV>I am sorry obviously i did not understand the question. I thought you
<DIV></DIV>wanted to manipulate the date/time stamp of the files, but you wanted to
<DIV></DIV>put a string to the filename. You can use the functions ctime() and
<DIV></DIV>time() of time.h in the style:
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>#include <STDIO.H>
<DIV></DIV>#include <STDLIB.H>
<DIV></DIV>#include <STRING.H>
<DIV></DIV>#include <TIME.H>
<DIV></DIV>
<DIV></DIV>int main(void)
<DIV></DIV>{
<DIV></DIV>char filename[]="some filename - ";
<DIV></DIV>time_t tp=time(NULL);
<DIV></DIV>char *s=ctime(&tp);
<DIV></DIV>char *newname=malloc(strlen(filename)+strlen(s)+1);
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>if(!newname)
<DIV></DIV>return EXIT_FAILURE;
<DIV></DIV>
<DIV></DIV>strcpy(newname, filename);
<DIV></DIV>strcat(newname, s);
<DIV></DIV>
<DIV></DIV>puts(newname);
<DIV></DIV>
<DIV></DIV>return 0;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>Keep in mind that this operation is portable, that is it works
<DIV></DIV>everywhere.
<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>-----Original Message-----
<DIV></DIV>From: dev...@li...
<DIV></DIV>[mailto:dev...@li...] On Behalf Of Ioannis
<DIV></DIV>Vranos
<DIV></DIV>Sent: Monday, February 25, 2002 8:42 PM
<DIV></DIV>To: Dev-C++
<DIV></DIV>Subject: RE: [Dev-C++] Time stamping an output file.
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>You can do it with win32 api:
<DIV></DIV>
<DIV></DIV>Syntax
<DIV></DIV>
<DIV></DIV>#include <IO.H>
<DIV></DIV>int getftime(int handle, struct ftime *ftimep);
<DIV></DIV>int setftime(int handle, struct ftime *ftimep);
<DIV></DIV>
<DIV></DIV>[ Useless things ]
<DIV></DIV>
<DIV></DIV></div><br clear=all><hr>Send and receive Hotmail on your mobile device: <a href='http://go.msn.com/bql/hmtag2_etl_EN.asp'>Click Here</a><br></html>
|
|
From: Benjamin W. <ben...@ho...> - 2002-02-28 13:05:42
|
<html><div style='background-color:'><DIV>
<P>Morning,</P>
<P>First of all, thanks again Ioannis and Jason for the suggestions.</P>
<P>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.</P>
<P>/*DATE STAMP TEST PROGRAM*/</P>
<P>#include <stdio.h><BR>#include <stdlib.h><BR>#include <time.h></P>
<P>int main()<BR>{<BR> FILE* testfile ;<BR> char* PtrToFname ;<BR> char FileName[27] ;<BR> time_t CurTime ;<BR> struct tm* datetime ;</P>
<P> CurTime = time( NULL ) ;<BR> datetime = localtime( &CurTime ) ;</P>
<P> strftime( FileName, 27, "C:\\temp\\hsloan%Y%m%d.txt", datetime ) ;</P>
<P> printf( "%s", FileName ) ;</P>
<P> PtrToFname = FileName ;</P>
<P> testfile = fopen( PtrToFname, "w" ) ;<BR> if( testfile == NULL )<BR> {<BR> printf( "\nUNABLE TO CREATE OUTPUT FILE! (ABNORMAL TERMINATION)\n" ) ;<BR> exit( 0 ) ;<BR> }</P>
<P> fclose( testfile ) ;</P>
<P> return 0 ;<BR>}<BR><BR>Thanks again everyone.</P></DIV>
<DIV></DIV>
<DIV><FONT face="Geneva, Arial, Sans-serif" size=2>Benjamin Wheeless</FONT></DIV>
<DIV></DIV>
<DIV><FONT face="Geneva, Arial, Sans-serif" size=2><STRONG>Network Systems - Delta Airlines, Inc.</STRONG></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><STRONG>Atlanta, GA - USA 30320</STRONG></FONT></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><STRONG>==============================</STRONG></FONT></DIV>
<DIV> </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: Mon, 25 Feb 2002 21:18:48 +0200
<DIV></DIV>
<DIV></DIV>I am sorry obviously i did not understand the question. I thought you
<DIV></DIV>wanted to manipulate the date/time stamp of the files, but you wanted to
<DIV></DIV>put a string to the filename. You can use the functions ctime() and
<DIV></DIV>time() of time.h in the style:
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>#include <STDIO.H>
<DIV></DIV>#include <STDLIB.H>
<DIV></DIV>#include <STRING.H>
<DIV></DIV>#include <TIME.H>
<DIV></DIV>
<DIV></DIV>int main(void)
<DIV></DIV>{
<DIV></DIV>char filename[]="some filename - ";
<DIV></DIV>time_t tp=time(NULL);
<DIV></DIV>char *s=ctime(&tp);
<DIV></DIV>char *newname=malloc(strlen(filename)+strlen(s)+1);
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>if(!newname)
<DIV></DIV>return EXIT_FAILURE;
<DIV></DIV>
<DIV></DIV>strcpy(newname, filename);
<DIV></DIV>strcat(newname, s);
<DIV></DIV>
<DIV></DIV>puts(newname);
<DIV></DIV>
<DIV></DIV>return 0;
<DIV></DIV>}
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>Keep in mind that this operation is portable, that is it works
<DIV></DIV>everywhere.
<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>-----Original Message-----
<DIV></DIV>From: dev...@li...
<DIV></DIV>[mailto:dev...@li...] On Behalf Of Ioannis
<DIV></DIV>Vranos
<DIV></DIV>Sent: Monday, February 25, 2002 8:42 PM
<DIV></DIV>To: Dev-C++
<DIV></DIV>Subject: RE: [Dev-C++] Time stamping an output file.
<DIV></DIV>
<DIV></DIV>
<DIV></DIV>You can do it with win32 api:
<DIV></DIV>
<DIV></DIV>Syntax
<DIV></DIV>
<DIV></DIV>#include <IO.H>
<DIV></DIV>int getftime(int handle, struct ftime *ftimep);
<DIV></DIV>int setftime(int handle, struct ftime *ftimep);
<DIV></DIV>
<DIV></DIV>[ Useless things ]
<DIV></DIV>
<DIV></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://go.msn.com/bql/hmtag_etl_EN.asp'>http://explorer.msn.com</a>.<br></html>
|
|
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
|
|
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>
|
|
From: Ioannis V. <no...@ya...> - 2002-02-28 15:28:09
|
-----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Benjamin Wheeless Sent: Thursday, February 28, 2002 4:06 PM To: dev...@li... Subject: RE: [Dev-C++] Time stamping an output file. Ioannis, 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. 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. 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. The file is created in the path you *are* the time the program is executed. E.g. if you are in MSDOS/Windows, your exe is placed as C:\c\temp.exe , you have C:\c in the path variable and you run it from any other directory e.g. C:\program files\microsoft\world\domination, the .txt will be created in C:\program files\microsoft\world\domination . If you want the output file to go always into the directory from where the .exe is run from, only then you *do* need to provide a path. Thanks for the analysis. Have a good day. Benjamin Wheeless Network Systems - Delta Airlines, Inc. Atlanta, GA - USA 30320 ============================== Thanks for the compliments. 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 |