Hi, i have written this block of code which deletes a record from a file, it works to some extent. i can delete existing records but at the second deletion and i display the file contents, i get some gibberish. also i cannot delete records which i have added to the file.
struct DATA
{
int ID;
char Item[30];
double price;
char comments[30];
};
DATA dim;
cout<<"Enter the id of the record you wish to delete: ";
cin >> id;
remove.seekg(id * sizeof(DATA));
remove.read(reinterpret_cast<char*>(&dim), sizeof(DATA));
dim.ID = 0; //i'm attempting to change the values for the record
strcpy(dim.Item, " "); //selected so i can then overwrite it to the file
dim.price = 0;
strcpy(dim.comments, " ");
remove.seekp(id * sizeof(DATA), ios::beg);
remove.write(reinterpret_cast<const char*>(&dim), sizeof(DATA));
remove << dim.ID << dim.Item << dim.price << dim.comments <<endl;
remove.close();