I would like to name my file descriptors, fp, based on the index of the for loop. For instance,
char* fbad[4]= "fbad";
char* mod[3]="mod";
for (int i=0; i<10; i++) {
sprintf(fbad_file, "%s%s%d", fbad,mod,i);
FILE *fp = fopen(fbad_file, "w"); ////????????????
/*then do stuff here*/
fclose(fp);
}
How does one concatenate *fp and i such shat the descriptor is unique for every file opened? For example, what I want to achieve is: for i=6, FILE *fp6.
Thanks in advance.
For example, what I want to achieve is: for i=6, FILE *fp6.Use an array:
Although, if you are closing the file pointer inside of the for-loop, what is the problem with reusing
fp?