Click to See Complete Forum and Search --> : delete a part of a file, only with SYSCALLS


Devotie98765
07-23-2002, 02:11 PM
Hello,
i 'm writing a Client/Server Application in C and i use Session ID's (int)to verify the Client. The SessionID's will be safed in one file.
When the Client is logged out, the Server must remove his SessionID from the file!
And there is my problem, i don't know, how i remove a int from the file, because i must use the Systemcalls, OPEN, READ, WRITE.

The Sessionfile look like this:

12345667,7654321,2134034

May anybody can give me a simple C example to remove a ID.

Many thanks

Martin

Energon
07-23-2002, 08:02 PM
Why are you stuck using only syscalls?

bwkaz
07-24-2002, 12:35 PM
Open the file, read the IDs in one at a time, and if they aren't the one you're deleting, write them back out (perhaps to a different file? I haven't thought through the details of this very much). If they are the one you're deleting, then continue the loop.

Or, open the file, read all the ID's except the to-be-deleted one into some sort of container (array, linked list, whatever, it doesn't matter), truncate the file (a.k.a. reopen it for writing, not appending) and write out the contents of the container.

Devotie98765
07-25-2002, 07:26 AM
Hy,

that's cool, it works,

many thanks

Martin

bwkaz
07-25-2002, 12:32 PM
Glad that it works, but as Energon asked, why can you only use syscalls?