Try this.
Code:
void delcust()
{
int x=0;
int i=0;
int currentid;
cout<<"Please enter the Customer ID you wish to delete: ";
cin>>currentid;
cin.get();
ifstream infile ("a:\\customerfile.txt",ios::in);
if (!infile)
{
cout<<"cannot open file";
return;
}
x=0;
while (!infile.eof())
{
infile.getline(c_file[x].surname,20,',');
infile.getline(c_file[x].firstname,20,',');
infile.getline(c_file[x].telephone,12,',');
infile >> c_file[x].custid;
infile.get();
if ((strcmp(c_file[x].surname,"")!= 0) && currentid != c_file[x].custid)
x++;
}
infile.close();
ofstream outfile("a:\\customerfile.txt",ios::out);
if (!outfile)
{
cout <<"cannot open file";
return;
}
for (i=0;i<x;i++)
{
outfile << c_file[i].surname << "," << c_file[i].firstname << "," <<
c_file[i].telephone << "," << c_file[i].custid << endl;
}
outfile.close();
}