Delete entry from file?

I use a text file to store data records. data is saved in the following format.

Antony | 9876543210
Azar | 9753186420
Branda | 1234567890
David | 1357924680
John | 6767676767

Thousands of records are stored in this file. I want to delete a specific entry, for example "David | 1357924680". I am using C, how to efficiently delete a specific entry? I am currently using a temporary file to copy entries to this temporary file, omitting the entry I want to delete. and after copying to the temp file, I copy the contents of the temporary file to the source file, trimming the entire contents of the source file. I do not think that I am doing this effectively. Help me.

+3
source share
6

, , (1) (0) :

Antony|9876543210|1
Azar|9753186420|1
Branda|1234567890|1
David|1357924680|1
John|6767676767|1

, :

Antony|9876543210|1
Azar|9753186420|1
Branda|1234567890|0
David|1357924680|1
John|6767676767|1

.

, , . , .

Edit

, , , .

+7

, . , sqlite. . sql . , ( ). : http://www.sqlite.org/. 3- , , , : http://www.sqlite.org/quickstart.html.

+5

:

  • temp , (, )
  • ( )
  • , , , , , ( , )
+2

, . .

I woud David|1357924680 |--------------- ( ).

  • ( )

  • . , .

- (, ,...) /, .

+2

:
1. , , , . .
2. "XXXXXXX" - . , .
3. . "" . , !

+1

, , , .

As mentioned by several others, maintaining the correct data structure and only repeating the recording at intervals will increase efficiency.

0
source

Source: https://habr.com/ru/post/1762438/


All Articles