Friends.
I am with the program segment below, and the following is happening.
If I take a while ( in bold ) to see if the code exists, the program writes records normally. If I leave this while, the program runs without error but does not record the record data in the file.
I can not figure out. I've tried everything. It has to do something with positioning end of file.
I need help on it.
Thanks.
void novo_registro(fstream &f)
{
int mcodigo,achei=0;
cliente c;
cout << "Digite codigo: ";
cin >> mcodigo;
// verifica se já existe o codigo
f.seekg (0, ios::beg);
while (! f.eof())
{
f.read((char *)(&c),sizeof(cliente));
if (c.codigo == mcodigo)
{
achei= 1;
break;
}
}