fprintf in directory

This is a discussion on fprintf in directory within the C Programming forums, part of the General Programming Boards category; Hi, Shoot me if I'm wrong but I can't find any concord information about this! How on earth will I ...

  1. #1
    1ST R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154

    Unhappy fprintf in directory

    Hi,

    Shoot me if I'm wrong but I can't find any concord information about this!
    How on earth will I be able to create a file in a directory relative to the program directory? I've tried a million different ways, like defining a prefix string, putting the directory in the line where info_filename is created, or in the line where test_info is opened... none of them seem to work. Find the snippets below:

    Code:
    now = time(NULL);
    struct tm *t = localtime(&now);
    
    mkdir("test_files");
    
    strftime(info_filename, sizeof(info_filename), "i_%d%m%y_%H%M%S.txt", t);
    strftime(data_filename, sizeof(data_filename), "d_%d%m%y_%H%M%S.dat", t);
    
    test_info = fopen(info_filename, "w");
    CAN_data = fopen(data_filename, "w");
    So I would like the txt and dat file to be created inside the directory test_files.
    Hope someone can help me out here! Thanks very much for any input.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Code:
    strftime(info_filename, sizeof(info_filename), "./test_files/i_%d%m%y_%H%M%S.txt", t);

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    concord information? What's concord information?
    Could it be Plane English or Fast Talking maybe?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  4. #4
    1ST R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Quote Originally Posted by Salem
    Code:
    strftime(info_filename, sizeof(info_filename), "./test_files/i_%d%m%y_%H%M%S.txt", t);
    Wish it was that simple really, I've tried that before but for some reason it doesn't work. Here's what I tried and what the result is:

    Code:
        strftime(info_filename, sizeof(info_filename), "./test_files/di_%d%m%y_%H%M%S.txt", t);
        strftime(data_filename, sizeof(data_filename), "d_%d%m%y_%H%M%S.dat", t);
    Result: i_090306_092822.td_090306_092822.dat (inside the test_files dir) and d_090306_092822.dat in the root.

    And if I try for both:
    Code:
        strftime(info_filename, sizeof(info_filename), "./test_files/di_%d%m%y_%H%M%S.txt", t);
        strftime(data_filename, sizeof(data_filename), "./test_files/d_%d%m%y_%H%M%S.dat", t);
    The program hangs....

    Any ideas?


  5. #5
    1ST R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Quote Originally Posted by WaltP
    concord information? What's concord information?
    Could it be Plane English or Fast Talking maybe?
    Here's what I get from the translator:

    English: Concord
    Dutch: concreet
    French: concret
    German: konkret
    Swedish: konkret
    Papiamento: konkreto


  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    English: Concrete

  7. #7
    1ST R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Quote Originally Posted by qqqqxxxx
    English: Concrete
    Is it really? Ok thanks! Lol, I used concord quite some times before due to that stupid translator

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Your strings are large enough I assume?

  9. #9
    1ST R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Quote Originally Posted by Salem
    Your strings are large enough I assume?
    Code:
    char info_filename[255], data_filename[255]
    Should be sufficient?

  10. #10
    1ST R. vd Kooij
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    154
    Damn... this is weird... cant remember having changed anything though it works now! I hate this....
    Anyway, thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 01:54 AM
  3. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 03:19 PM
  4. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 09:33 PM
  5. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 08:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21