View Single Post
Old 07-18-2005, 10:52 AM   #1 (permalink)
Jakejake
Crazy
 
[C] Incremental string updates - 00001.png 00002.png etc

Hi,
I am writing a program in C that will be outputting a lot of files that I want to be named 00001.png 00002.png 00003.png and so on.

The way I am doing it at the moment is as follows:

Code:
        for(i=0; i < 10000; i++)
        {
                filename[4]++;
                if(filename[4] > 57)
                {
                        filename[4] = 48;
                        filename[3]++;
                        if(filename[3] > 57)
                        {
                                filename[3] = 48;
                                filename[2]++;
                                if(filename[2] > 57)
                                {
                                        filename[2] = 48;
                                        filename[1]++;
                                        if(filename[1] > 57)
                                        {
                                                filename[1]++;
                                        }
                                }
                        }
                }
                //CODE THAT WRITES TO FILE USING filename
        }
Now this seems a rather ugly way to do it. What I should be doing is simply incrementing an integer and then converting that to a string somehow, but I can't work out how to do this.

Any ideas?

Thanks

Robbie

Last edited by Jakejake; 07-18-2005 at 10:52 AM.. Reason: typo
Jakejake is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54