Generating data file names from program variables

This is a discussion on Generating data file names from program variables within the C Programming forums, part of the General Programming Boards category; Hi Everybody, I am writing a C program for numerical scheme. Now, based on the input parameter, I am trying ...

  1. #1
    Registered User a380x's Avatar
    Join Date
    Dec 2006
    Posts
    2

    Question Generating data file names from program variables

    Hi Everybody,

    I am writing a C program for numerical scheme. Now, based on the input parameter, I am trying to generate data file name. For example, suppose grid size defined by N is 50 i.e. N = 50, and if I can include this grid size in the data file e.g. ums_50.dat, then as we change the parameters, they will automatically be reflected in the file name. Let's say we make N = 60, then code should generate file ums_60.dat and so on.

    We can also have more than one parameters in the file name. I did write a code which is a bit involved and not giving desired output.

    Any relevant suggestions will be appreciated.

    Thanx in advance.

    Maverick

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    show your code

    use sprintf
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User a380x's Avatar
    Join Date
    Dec 2006
    Posts
    2

    Thumbs up

    Hi Vart,
    That was really simple. Getting the required results.
    Thank you so much.
    Here's a snippet I quickly wrote using sprintf().
    Code:
        int     N,i,j;
        char    string[50];
        double  lambda;
        N       = 100;
        i       = 10;
        j       = 20;
        lambda  = 0.01;
        sprintf( string, "i=%d_j=%d_N=%d_lambda=%0.3f.dat", i,j,N,lambda);
        fp1 = fopen( string, "w" );
    Output:
    i=10_j=20_N=100_lambda=0.010.dat

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 02:04 PM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Writing and modifying data in a file
    By Micko in forum C Programming
    Replies: 2
    Last Post: 02-17-2005, 03:42 AM

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