Thread: Timestamp as filename

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    6

    Timestamp as filename

    Ok, one more probably stupid question but how would I get the current time and use that to create a new file with the timestamp as the name of the file?

  2. #2
    Registered User GL.Sam's Avatar
    Join Date
    Aug 2009
    Posts
    88
    There is a time() function declared in a header file <time.h>. Check your compiler manual for further instructions concerning its value. And please ask all of your questions in one thread named like "My beginner questions".
    The only good is knowledge and the only evil is ignorance.
    ~Socrates

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    8

    time.h

    I was looking for the same a few weeks ago, wth help from the forume i made it.
    ctime (time.h) - C++ Reference

    did something like this:
    remember to include time.h
    Code:
     time_t rawtime;
          struct tm * timeinfo;
          char buffer [80];
    
          time ( &rawtime );
          timeinfo = localtime ( &rawtime );
    
          strftime (buffer,80,"Sample-%b%d_kl_%H%M.txt",timeinfo);
          puts (buffer);
        
       FILE *fil1,*fil2;
        fil1=fopen(buffer,"w");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-11-2009, 01:49 AM
  2. Pass Filename to another function
    By awesmesk8er in forum C Programming
    Replies: 9
    Last Post: 10-24-2008, 01:43 PM
  3. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 03:36 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Replies: 3
    Last Post: 01-25-2006, 10:30 PM