Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to add time stamp a text file?

Posted on 2003-02-24
6
Medium Priority
?
321 Views
Last Modified: 2010-04-17
I am trying add time stamp to a text file to prevent it over written.


The example below allow user to save to a same file called group.txt.  but if 2 or more
user run the program the file group.txt will be over written.  Is it a way to save
the group.txt more than one version using time stamp?

Here is the example:

FILE *myfile;

myfile = fopen("/home2/user/tmp/group.txt", "w");
        fprintf (myfile, "%s\n", "Testing..testing..testing");
        fclose (myfile);
       
Thanks.
0
Comment
Question by:malaou
5 Comments
 
LVL 16

Accepted Solution

by:
twalgrave earned 100 total points
ID: 8009537
you will have to rename the file using the timestamp information so group.txt becomes group_2003_02_24_1015.txt.

Alternatively, you can write each person's file in a different location

Still yet, you can append to the file instead of overwriting and put in the the userID upon each write and search it by userid.
0
 

Author Comment

by:malaou
ID: 8009688
Hi twalgrave,

How to rename the file using the timestamp information so group.txt becomes group_2003_02_24_1015.txt??

Please provide some example.

Thanks.
0
 

Assisted Solution

by:vpomona
vpomona earned 100 total points
ID: 8010143
char buffer[10];
GetSystemTime(&LocalSystemTime);
CString     FileName= _itoa(LocalSystemTime.wDay,buffer,10);
     FileName += _itoa(LocalSystemTime.wMonth,buffer,10);
     FileName += _itoa(LocalSystemTime.wYear,buffer,10);
     FileName += _itoa(LocalSystemTime.wHour,buffer,10);
     FileName += _itoa(LocalSystemTime.wMinute,buffer,10);
0
 

Expert Comment

by:vpomona
ID: 8010147
char buffer[10];
GetSystemTime(&LocalSystemTime);
CString     FileName= _itoa(LocalSystemTime.wDay,buffer,10);
     FileName += _itoa(LocalSystemTime.wMonth,buffer,10);
     FileName += _itoa(LocalSystemTime.wYear,buffer,10);
     FileName += _itoa(LocalSystemTime.wHour,buffer,10);
     FileName += _itoa(LocalSystemTime.wMinute,buffer,10);
0
 

Expert Comment

by:CleanupPing
ID: 9447541
malaou:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question