Help in outputing different file names in a loop

This is a discussion on Help in outputing different file names in a loop within the C++ Programming forums, part of the General Programming Boards category; I got this program here which is suppose to output a .ppm file. How can i modify the Filename to ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    Help in outputing different file names in a loop

    I got this program here which is suppose to output a .ppm file. How can i modify the Filename to get an output of out1.pmm, out2.pmm, out3.pmm .. so on and so forth for a while loop?

    Code:
    unsigned char Filename = "out1.ppm";
    
    while (i < 100)
    {
    
    FILE *stream;
    
    stream = fopen(Filename, "wb" );                     // Open the file for write
    
    //rest of the program;
    //..
    //..
    
    }

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Code:
    #include <sstream>
    // ...
    
    std::stringstream ss;
    
    while (i < 100)
    {
      ss << "out" << i << ".ppm";
      FILE *stream;
    
      stream = fopen(ss.str().c_str(), "wb" );   // Open the file for write
      ss.str("");                                // clear the stringstream
    //rest of the program;
    //..
    //..
    
    }

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    if this is C++ you probably need to use fstream instead of FILE*

    If this is C - you should ask on the proper forum
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Kung Fu Kitty Angus's Avatar
    Join Date
    Oct 2008
    Location
    Montreal, Canada
    Posts
    115
    There's no such need. Iostream laid the last straw on my camel a long time ago. I use stdio.h all the time.

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, 12:44 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM

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