I am using a random access file in which i want to delete a line which satisfies some condition like if i have records
MCA 30
MBA 20
BCA 10
now my requirement is if i enter MBA then second line is to be deleted.
I am using a random access file in which i want to delete a line which satisfies some condition like if i have records
MCA 30
MBA 20
BCA 10
now my requirement is if i enter MBA then second line is to be deleted.
Generally, removing an item from the middle of the file means rewriting all entries after the entry so as to use the space the item occupied.
Some things instead mark items that are deleted with some invalid value so as to spot that the slot is unused. Typically they don't even reuse deleted slots, as this is rather more management than you might imagine, and is basically implementing a heap-like architecture in a file. They need a separate 'compacting' step to remove this dead space later. Microsoft Jet (as in Access) worked like this.
There's a very cool optimisation that's applicable in some cases:
If the rows are unordered, and equal length, you can overwrite the entry you want to 'delete' with the last entry, and truncate the file.
If the rows are unordered but not fixed length, you can use a more complicated variant of this approach where you move some entry from near the end that is the same length as the item being removed, so as only to need to shuffle up as few entries as possible.