I am trying to write code that will open and modify multiple files with similar prefixes and different "numbers," ie, data001, data002 etc. I have written something that I thought would work, but it seems to be faulty, please help.
Code:
int main(void)
{
//these are the variables. You need to put your data files in the folder where this is compiled
//m->slope, x->velocity, y-> number of counts and sums.
//n->number of points in background
double m, x, y;
double leftend, rightend; /*these define the region where there is absorption*/
int n=0, numpoints;
FILE *in; /* our file pointer */
/* the file name (we'll change the number later) */
FILE *newfold; /*the output file*/
char *fname = "data000.txt";
char *output = "folded000.fld";
/* the digits as characters */
char digit[10] = {'0','1','2','3','4','5','6','7','8','9'};
int i; /* this is our counter */
int d1; /* this is the hundreds digit */
int d2; /* this is the tens digit */
int d3; /* this is the ones digit */
printf("At what velocity does the absorption begin? (mm/s): ");
scanf("%lf", &leftend);
printf("At what velocity does the absorption end? (mm/s): ");
scanf("%lf", &rightend);
for( i = 1; i <= 100; i++ ){
d1 = i/100; /* form file name */
d2 = (i - 100*d1)/10;
d3 = (i - 100*d1 - 10*d2);
printf("d1 = %d, d2 = %d, d3 = %d\n", d1, d2, d3);
/*the program crashes after this step*/
fname[4] = digit[d1]; /* assume less than 999 files */
thanks in advance
Josh