Thread: fprintf in a double while loop

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    fprintf in a double while loop

    Hello everybody,

    I'm new here, 27, French and have already a question for you!

    I have a double "while" loop, while(k)(while(i)()).

    In the "i" one, I use "fprintf" to write into a file "out_x".
    In the "k" one, I would like to change automatically the name of the file (more precisely the "x") I will write in, before the next entry into the loop "i" again.

    In summary I would like to write into "kmax" files, named "out_k" up "out_kmax" automatically.


    Do you have any idea how I can do this?

    Thanks in advance,

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    use sprintf to generate a string that you want the file to be named on each iteration, and call fopen with this string in write mode each round of the loop. Make sure you close the files after each iteration.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    I'll try this tonight, thanks a lot for your fast answer!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions, have errors...NEED HELP FAST
    By alkamenes in forum C++ Programming
    Replies: 6
    Last Post: 11-02-2009, 03:00 PM
  2. Help me please.
    By yann in forum C Programming
    Replies: 15
    Last Post: 09-29-2009, 09:04 PM
  3. Replies: 8
    Last Post: 12-01-2008, 10:09 AM
  4. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  5. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM