This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

fseek() question

I'm posting this question here since Keil's support haven't answered my email so far:
----------------------------------------
I have the following piece of code:

fH = fopen(FILE_NAME_CLOCK, "a");
fseek(fH,20,SEEK_SET);
fwrite(jbuf,1,sizeof(jbuf),fH);
fclose(fH);


It is supposed to write to position 20 right, but if you look at the attached file it appends the data to the end of the file. What am I missing or doing wrong or is it a bug?

PS: Using Keil's RTK file system and µVision3 V3.80 on a ARM7 from NXP.

Parents
  • Thanks Christoph, I read Keils documentation which mentions nothing about differences in opening text or binary files or using the "+" option. But I changed my code anyway to:

    fH = fopen(FILE_NAME_CLOCK, "ab");
    rewind(fH);
    fwrite(jbuf, 1, sizeof(jbuf), fH);
    fclose(fH);
    


    As you can see I replaced fseek() with rewind() - and still it appends the string to the end of the file!

    Is there someone who actually used Keil's file system before and how did you write to an arbitrary location inside the file?

Reply
  • Thanks Christoph, I read Keils documentation which mentions nothing about differences in opening text or binary files or using the "+" option. But I changed my code anyway to:

    fH = fopen(FILE_NAME_CLOCK, "ab");
    rewind(fH);
    fwrite(jbuf, 1, sizeof(jbuf), fH);
    fclose(fH);
    


    As you can see I replaced fseek() with rewind() - and still it appends the string to the end of the file!

    Is there someone who actually used Keil's file system before and how did you write to an arbitrary location inside the file?

Children