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 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>
|