#Generate all possible combinations between 00000000 and 99999999 and write into a file

23 messages ยท Page 1 of 1 (latest)

topaz lantern
#

Hello, I would like to generate all the possible combinations of the number "00000000" to "99999999" and write them to a file, for this I have made this code, but it does not work and no error is thrown. Could you help me more to find the problem please? Maybe I do it the wrong way. Thank you ^^

#include <stdio.h>
#include <stdlib.h>


int main(void) {
    FILE* fp;

    fp = fopen("numlist.txt", "a");

    for (int a = 0; a < 10; a++) {
        for (int b = 0; b < 10; b++) {
            for (int c = 0; c < 10; c++) {
                for (int d = 0; d < 10; d++) {
                    for (int d = 0; d < 10; d++) {
                        for (int e = 0; e < 10; e++) {
                            for (int f = 0; f < 10; f++) {
                                for (int g = 0; g < 10; g++) {
                                    for (int h; h < 10; h++) {
                                        fprintf(fp, "%d%d%d%d%d%d%d%d;", a, b, c, d, e, f, g, h);
                                    }
                                }
                            }                    
                        }
                    }
                }
            }
        }
    }
    return EXIT_SUCCESS;
}
dreamy runeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

topaz lantern
#

Maybe it is too much ? (10^8) * 9 chars would be too much ?

glossy adder
#

;cpp << log10(99999999)

wet dawnBOT
#
Program Output
8
glossy adder
#

9 * 100 million, you're looking at 900 MB

#

It's a lot but not too much

topaz lantern
#

๐Ÿ‘

glossy adder
#

Maybe try "w" instead of "a" though

topaz lantern
#

ok i will try ๐Ÿ™‚

glossy adder
#

Assert that fopen and fprintf aren't failing, don't forget to fclose

topaz lantern
#

This is returned by the fprintf on each iter

10;10;10;10;10;10;10;10;10;10;%
#
#include <stdio.h>
#include <stdlib.h>


int main(void) {
    FILE* fp;

    fp = fopen("numlist.txt", "w");

    if (fp == NULL) {
        printf("Can't open file");
        exit(1);
    }
    for (int a = 0; a < 10; a++) {
        for (int b = 0; b < 10; b++) {
            for (int c = 0; c < 10; c++) {
                for (int d = 0; d < 10; d++) {
                    for (int d = 0; d < 10; d++) {
                        for (int e = 0; e < 10; e++) {
                            for (int f = 0; f < 10; f++) {
                                for (int g = 0; g < 10; g++) {
                                    for (int h; h < 10; h++) {
                                        int fpf = fprintf(fp, "%d%d%d%d%d%d%d%d", a, b, c, d, e, f, g, h);
                                        printf("%d;", fpf);
                                    }
                                }
                            }                    
                        }
                    }
                }
            }
        }
    }
    fclose(fp);
    return EXIT_SUCCESS;
}
#

(The thing i made to see)

tame linden
#

Why would you do it with so many nested for-loops?
Just do:

for (int i = 0; i < 99999999; ++i)
    fprintf(fp, "%08d", i);
#

;compile

for (int i = 0; i < 10; ++i)
    printf("%08d\n", i);
wet dawnBOT
#
Program Output
00000000
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
00000009
topaz lantern
#

You're right !

#

I'm so stupid

#

Thank you very much !!

#

!solved

dreamy runeBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] Generate all possible combinations between 00000000 and 99999999 and write into a file