The way to delete a record is --- well actually -- you don't wanna delete it.
As it turns out, it's great having some deleted records in your database. Because that's where you will stick in new records, without having to shift all the rest around, as much.
For a deleted record, just remove the primary key - whether it's an ID number set to zero, or whatever. Also, put an end of string char as the first char in the name field:
Smith, becomes \0mith. Now you have these deleted records in your data file, so you set your printing function not to print empty records:
Code:
for(i = 0; i < MaxNumber; i++) {
if(ID) {
printf("\n Name: %s ID: %d Phone Number: %s", recs[i].name, recs[i].ID, recs[i].phone);
}
}
When you need to add a record, you just have your add function locate an already empty slot:
Code:
for(i = 0; i < MaxNumber; i++) {
if(ID == 0) {
//found one that's empty, add the record data code right here
}
}
What have we accomplished with this? We just shift our records around, a lot less. Make a few adjustments to our code, and we're good to go. It's easy enough to shift records, but when you have a large number of records, it's just not what you want to waste computer time, doing.