?
Solved

How to add time stamp a text file?

Posted on 2003-02-24
6
Medium Priority
?
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans
Suggested Courses

777 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