hi there. New to the forums here so I apologise if this thread is in the wrong place
I've written a program that opens a text file and reads the data off it, and allows you to edit the information or add more stuff thats to it. When I go to save it, it asks for the filename to save it under, gives a little update on what you're saving, and then saves it.
So far it does all of that apart from save the file. When I go to save it, the size of the text file just keeps on increasing till my hard drive is full. It recon it must be looping the data that is sent to the text file somewhere but I don't know where.
Here's the part of my code that I use to save it, if I've not given enough of the code, just say I'll post more.
Code:
// SAVE STOCK DETAILS TO A TEXT FILE
void save_items( int numitems)
{
//char filename [12];
cout << "Type the name of the data file... ";
cin >> filename;
cout << "this is the file name.." << filename << "\n";
system ("pause");
int i = 1;
FILE *out_file;
cout << "\n\t\tDefault filename is " << filename << " with " << numitems-1
<< " items\n";
cout << "\n\t\tSaving " << filename << ".......";
waitforkey( );
out_file=fopen(filename,"w");
do
{
fprintf(out_file,"%7d %25s %25s %7d %7.2f \n", slist[i].stocknumber,
slist[i].description, slist[i].supplier, slist[i].quantity,
slist[i].price);
i = i++;
}
while (i <= numitems-1);
cout <<"\nSaved a total of" << i-1 << " items\n";
fclose (out_file);
}