Mail Archives: djgpp/2009/03/24/00:10:59
Dear list -
I have a program that opens almost 30 files. My config.sys has
files=50. The function listed below is where the problem is. It
runs perfectly when there are approx less than 20 writes to each of
the file pointers. With fptr27 and fptr25, after approx 20 writes,
it gives garbage. When I examine the output from the write, [fptr27
and fptr25], the beginning approx 20 lines of the output is OK, and
then garbage. The sprintf function works perfectly. I have stepped
thru the program and seen that the fwrite function is getting the
correct input. I have checked the function with splint, and it finds
no errors.
Is this a problem with my setup, or DJGPP? What would be a
work-around? As you can see in the code below, I have tried to
explicitly state the point of the write; eg, &instring7[0] and have
also tried to use fflush, to no avail. The problem is with the
variables ga and dl_avg. [fptr27, fptr25]
I open all the files in main, and check for an error condition on
open, rather than opening in a function.
Advice please.
Here is the code:
===========
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
extern FILE *fptr12, *fptr14, *fptr17, *fptr11, *fptr25, *fptr27, *fptr28;
extern int num_ctxns;
extern float gamma_avg, gamma2_avg, delta_avg;
extern float alpha_avg;
double instring6[2], instring7[2];
double instring[2],instring2[2], instring3[2], instring4[2],
instring5[2]; /* Temporary input string */
int disp_ctg2(float min, float delta, float alpha, float gamma2,
float gamma3, float ga)
{
static int counter = 0;
static char string[6][81];
static int i = 0, first = 1;
int j;
static float ga_avg, ga_avg_sum, ga_sum, gam_sum, alph_sum,
gam2_sum, dll_sum, alp_sum;
counter++;
sprintf(string[i],"CX#%3d: Min %4.2f Delta %.4f Alpha %.2f G1
%.2f G2 %.2f GA %.2f\n",\
counter, min, delta, alpha, gamma2, gamma3, ga);
if(first)
{
first = 0;
gamma_avg = 0.0;
gamma2_avg = 0.0;
gam_sum = 0.0;
gam2_sum = 0.0;
delta_avg = 0.0;
ga_avg = 0.0;
ga_avg_sum = 0.0;
dll_sum = 0.0;
alpha_avg = 0.0;
alp_sum = 0.0;
ga_sum = 0.0;
}
gam_sum += gamma2;
dll_sum += delta;
alp_sum += alpha;
gam2_sum += gamma3;
ga_sum += ga;
dll_sum += delta;
delta_avg = dll_sum/counter;
ga_avg = ga_sum/counter;
gamma_avg = gam_sum/counter;
gamma2_avg = gam2_sum/counter;
alpha_avg = alp_sum/counter;
instring[0] = (double)min;
instring[1] = (double)delta;
fwrite(instring, (size_t)sizeof(double), 2, fptr14);
instring2[0] = (double)min;
instring2[1] = (double)alpha;
fwrite(instring2, (size_t)sizeof(double), 2, fptr12);
instring3[0] = (double)min;
instring3[1] = (double)gamma2;
fwrite(instring3, (size_t)sizeof(double), 2, fptr17);
instring4[0] = (double)min;
instring4[1] = (double)gamma3;
fwrite(instring4, (size_t)sizeof(double), 2, fptr11);
instring5[0] = (double)min;
instring5[1] = (double)ga;
fwrite(&instring5[0], (size_t)sizeof(double), 2, fptr25);
fflush(fptr25);
instring6[0] = (double)min;
instring6[1] = (double)ga_avg;
fwrite(&instring6[0], (size_t)sizeof(double), 2, fptr28);
fflush(fptr28);
instring7[0] = (double)min;
instring7[1] = (double)delta_avg;
fwrite(&instring7[0], (size_t)sizeof(double), 2, fptr27);
fflush(fptr27);
i++;
if(i == 6)
{
strcpy(string[0],string[1]);
strcpy(string[1],string[2]);
strcpy(string[2],string[3]);
strcpy(string[3],string[4]);
strcpy(string[4],string[5]);
strcpy(string[5],string[6]);
i = 5;
}
for(j = 9; j < 14; j++)
{
gotoxy(1,j);
clreol();
}
gotoxy(1,9);
for(j = 0; j < 5; j++)
printf("%s",string[j]);
return counter;
}
===========
Thanks.
Ethan Rosenberg
- Raw text -