Thread: Writing Files with a Timestamp - Extras appearing

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    California
    Posts
    19

    Writing Files with a Timestamp - Extras appearing

    Hi Everyone,

    Been a while since I've posted on here!

    So, I'm working on some C code for a data acquisition system to read out PMTs. That part hasn't been too bad, but I'm having a weird issue with writing the data out to a file.

    When I have a test case set up, I should write a 120 kB to a file that's timestamped with the time the program runs.

    However, my problem is that when I write the file, it writes a number of files with a new seconds timestamp! Each one is 120kB! It's absolutely baffling to me.

    Here's some code:

    I find the timestamp this way:

    Code:
    time(&curr_time);
    time_info = gmtime(&curr_time);
    
    strftime(new_time, 80, "%a_%b_%d_%Hh_%Mm_%Ss", time_info);
    When I sprintf this string into a filename and write it, it writes what seem to be 6 files (or more, depending on how many seconds the program runs.) which look like so:

    test_prefix_Tue_Jan_24_18h_25m_18s_suffix.dat
    test_prefix_Tue_Jan_24_18h_25m_19s_suffix.dat
    test_prefix_Tue_Jan_24_18h_25m_20s_suffx.dat
    test_prefix_Tue_Jan_24_18h_25m_21s_suffix.dat

    Where the first file is the filename I actually created, opened, and wrote.

    What's weird is that, if I drop the %S modifier in the format string, there is only one file written at that particular time. This file is then the correct one.

    Moreover, what's more weird is that if I print out every single time I close a file, there's only one fclose and one fopen operation in my program.

    This problem is totally baffling to me. I'm using Microsoft Visual Studio C++ (and associated compilers) to develop this code (even though it's in C) since I need to be making DLLs to link into a Labview program. Is this a windows development environment kind of thing? Is the nature of the memory assigned for the time object and string tripping me up here?

    Thanks for any help!

  2. #2
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Looks fine from here, but from your description I get the impression that you're overflowing something somewhere. Could you show us how the files are opened? Is that happening inside a loop? If yes, show the code of the entire loop.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    California
    Posts
    19
    Thanks for the input, but I walked away from the problem then came back, and then it was working perfectly.

    I think that it was a buffer issue since I had developed it all in one session, and I've added a fair amount of fflush() commands now. If it starts acting weird again, and / or I figure out that it was due to a different reason, then I'll post and let you know!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is this a timestamp?
    By NewnOT in forum Tech Board
    Replies: 11
    Last Post: 09-21-2010, 03:41 PM
  2. including my extras.h file. errors
    By aliaseer in forum C++ Programming
    Replies: 12
    Last Post: 05-27-2009, 05:25 PM
  3. about timestamp
    By George2 in forum C Programming
    Replies: 2
    Last Post: 08-16-2006, 06:59 AM
  4. access timestamp
    By Jalabert in forum Windows Programming
    Replies: 2
    Last Post: 06-02-2005, 08:02 AM
  5. Extras for help
    By perfect12 in forum C Programming
    Replies: 1
    Last Post: 12-10-2001, 04:21 PM