I have a structure set up from some earlier help. Now when I try to write the data to the disk I only write zero's. I have no idea what I have done wrong or why this is happening. I realize this is not the complete program but shows the structure setup. then the disk write section. If I capture say 3 sets in the program I can print them to the screen with the correct data the disk file shows this

0,0,0,0,0,0
0,0,0,0,0,0
0,0,0,0,0,0



struct batch
{
int a,b;
double  c,d,e;
int f;
};


struct batch batch [2000];
int temprec=0;


int w;
BatOut=fopen("batch1.csv","w");


if (BatOut==NULL)
{
clrscr();
gotoxy(12,10);
cprintf("Disk Error");
}
else
{
for(w=0;w<=temprec;w++)
{
fprintf(BatOut," %d, %d, %g, %g, %g, %d\n",
batch[temprec].a, batch[temprec].b, batch[temprec].c,
batch[temprec].d, batch[temprec].e, batch[temprec].f);
}


}


fclose(BatOut);

It seems you may want to set temprec equal to 2000 before the loop and use w as your array index inside the fprintf statement.

Best of luck,
Mage

and use "<" not "<=" in the for loop

It seems you may want to set temprec equal to 2000 before the loop and use w as your array index inside the fprintf statement.

Best of luck,
Mage

I can't set temprec at 2000 it's my counter as the records a moved in to the batch structure. the fprint satement loops it just prints zero's instead of data

Ok, then just use w as the array index

Thanks, honestly I just could not see that. Maybe I should lay off the coffee until I get this done.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.