0

I have a bunch of files systematically numbered like Mesh0Coord.dat, Mesh0Elem.dat, Mesh1Coord.dat, Mesh1Elem.dat, etc. This is what I want to do:

int ID;
FILE *fp;

ID = 0; /* could be 0, 1, 2, etc. and so on for the names of the files */

fp = fopen(“Mesh[ID]Coord.dat”, “r”);

The Mesh[ID]Coord means that the ID integer should be inserted there. Any tips?

Natan Streppel
  • 5,759
  • 6
  • 35
  • 43
user1799323
  • 649
  • 8
  • 25

1 Answers1

6
#define MAXFILENAME 100

int ID;
char fn[MAXFILENAME+1];

ID = 10;    
snprintf(fn, MAXFILENAME, "Mesh%dCoord.dat", ID)

fp = fopen(fn, "r");
codnodder
  • 1,674
  • 9
  • 10