Question : C loop string cat a file name + int n loop

I am trying to make a more elegant routine for opening 20 files.  I have to open the files from different handlers, so I should make this more useful rather then a piece of junk! :-)  Maybe 3 times I need to reopen the files...one time it will be a writer rather then a reader.

So far I am naming my FILE *fp in a series and also naming my FILENAMES in a series:

FILE *fp
FILE *fp2
...
etc.

FILENAMES:
file1
file2
file3

String Cat seems easy, but I haven't worked in C language for several years and I'm crashing and burning and it's simple, mostly, BUT HELP would be greatly appreciated.

Loop Routinine, increment 'n'
cat, and cast that onto "fp" or "file" + (char*)n + '\0' at end of string for File name.

I got something to compile, but it segfaults...can't even printf out what I concatenated, so something is weird and wrong with what I'm doing...

Answer : C loop string cat a file name + int n loop

>> FILE *fp
>> FILE *fp2

Why not make that an array of FILE* ?

        FILE* fp[20] = { 0 };


>> file1
>> file2
>> file3

Why not use sprintf (or something similar) ?

        char filename[64] = "";
        sprintf(filename, "file%d", index);

where 'index' is the number of the file (1, 2, etc.)
Random Solutions  
 
programming4us programming4us