I had a look at vector, set and deque. I had problems with all of
them.
My data is a structure, I need to be able to add and delete items, and
then write them to disk, and then load them again, and then add/
delete.
I am happy with adding to and removing from a DynamicArray, I have
experience with that from Visual Basic and Pascal.
I now have a problem with writing to and reading from the file.
To write I use
FileHandleI=open("EventData.dat",O_CREAT | O_RDWR | O_TRUNC |
O_BINARY);
y=errno;
for (x=0;x<NumEvents;x++)
{
BytesWritten=write(FileHandleI,&EventSet[x],sizeof(EventType));
y=errno;
}
close(FileHandleI);
If the file doesn't exist (first run) FileHandleI is 3, errno is 6
(bad file number) on opening the file, BytesWritten is correct and
errno is set to 7 (memory blocks destroyed).
If I check the file with a hex editor, it is correct.
To reopen the file I use
FileHandleI=open("EventData.dat",O_RDONLY);
y=errno;
if (FileHandleI!=-1)
{
NumEvents=filelength(FileHandleI)/sizeof(EventType);
if (NumEvents>0)
{
EventSet.Length=NumEvents;
for (x=0;x<NumEvents;x++)
{
read(FileHandleI,&EventData,sizeof(EventType));
y=errno;
EventSet[x]=EventData;
}
}
}
close(FileHandleI);
No error on open or read, data is correct.
However, now writing to the file (with or without adding data),
opening the file gives FileHandle -1 and errno 5 (permission denied).
If I try to use S_IWRITE and S_IWRITE (as the documentation suggests)
the compiler doesn't recognise them. Using Search, the only unit I can
find with them in is stats.h, but that is a refernce not a
declaration.
Until I get the file routines sorted, I am not going to get far with
the app.