What is the simplest way of maintaining a txt based database file that allows the program the write in new or edit existing entry during execution time.
to be specific, the program must be capable of storing a client, ip and port when it logs in, and remove accordingly when the client logs out, without using “internal” approaches like linkedlists.
EDIT: thanks first to the suggestions, however there is a restriction in the file that i forgot to mention, the file must be in .txt format.
the exact format is
User Name IP Address Port Number
Alice 122.33.44.23 1045
Bob 121.23.12.34 1078
which different field must be separated by a
Installing a database as several other posters have suggested will buy you certain things such as transaction security and the possibility of expanding what you store (at the moment, you need just IP/port, but maybe later you’ll store more things, and maybe more permanently?)
However, if your requirements are going to remain as simple as you state, then I’m going to controversially suggest that using a SQL database isn’t the simplest solution (even though, as I say, for certain requirements, a database does buy you certain things).
A very simple solution would be simply to have some directory in which, every time a client logs in, you create a file whose name encodes the information you want (or a hash of identifying information, and store extra info in the file). Then, when the client logs off, you delete the file. Issues you’ll need to be careful of include what happens when your app exits abnormally, splitting among several directories if you have more than, say, a couple of thousand clients (Windows in particular seems to go ape if you have too many files in a directory, even though principle you should be able to store as many as you like), and managing filing system “issues” (the virus checker is accessing a file just as you need to delete…).
This simple solution isn’t actually as bad as it sounds: the filing system is actually designed to access and index things efficiently, just like a database.