C File Clugger....

Programming, for all ages and all languages.
Post Reply
Cjmovie

C File Clugger....

Post by Cjmovie »

ugh....

I've wrote (or really, trying to write) a system which takes entrys (of about 10kb) and stores them in a single file. Basically each entry has a 50-byte name, and to find it it will load until the name entry in the loaded temporary class instance is what it's looking for.

The problem is, when It goes back to write it/update it in the file (some time later, after closing the file, it has to open it again) it writes it in the right place, but all the other data has mysteriously...turned into remnants of files that have been deleted (of course I know that's becuase windows only erases FAT entries, not the entire file).

I get to the position in the file by taking the index variable (p), multiplying it by the size of each entry (about 10,760 bytes) and then using fsetpos(fp, pos);
Of course I do something like this really:

f_pos Pos = p*sizeof(History);
fsetpos(fp, &Pos);

The file is opened for write-only in binary mode.
AR

Re:C File Clugger....

Post by AR »

Opening in write-only is probably what's done it, try append.
Cjmovie

Re:C File Clugger....

Post by Cjmovie »

Hmm, when I do append it seems like it's FORCING me to save at the end...I've tried fseek, fsetpos, even a rewind before I save :(.
Cjmovie

Re:C File Clugger....

Post by Cjmovie »

Hmm...I think I get it now.

I was opening it with "wb", so it probably thought I wanted to start from scratch, but if I use "r+b", that makes it think I want to read AND write, but not create ("w+b" being read and write, but create, i guess)

It seems to work, I'll try it some more.
Post Reply