Re: File Handling
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 21 Mar 2007 20:31:38 GMT
Mr B <mrb_16@xxxxxxxxxxx> wrote:
Hi all,
I hoping somebody will be able to help me this a tedious problem I'm
having which I just can't seem to get right.
I open this file as a file I want to read and write to, it holds an
integer value.
I want to do this repeatedly, in this order:
1. fopen the file
2. read the value from the file
3. write a value to the file (overwriting the previous interger so
before there was 1 value, and after there is 1 value, the new one)
4. fclose the file.
fCurrProduction = fopen(CurrentProduction,"w+");
I have tried this way, but everytime i come to read from it in step 2
nothing exists in the file even though there was before the program
was run, it seems to wipe the value.
fCurrProduction = fopen(CurrentProduction,"r+");
This way seems to append the file when I want to overwrite
But only if you first read but then don't rewind to the start
of the file - after the read your at the position after what
you just have read. Use either rewind(3) or fseek(3) to repo-
sition back to the start of the file and everything should
work.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- References:
- File Handling
- From: Mr B
- File Handling
- Prev by Date: File Handling
- Next by Date: Re: Is splint the best for static code checking? I mean free.
- Previous by thread: File Handling
- Index(es):