fseek failure in Borland compilers?!?!?!

Hi, I'm writting a text editor in C, and I have a problem.
I isolated the problem to the next simple program:
first, I work with bin files,and when writting to the file or reading,
it's by Str[73].
suppose that we prepared a file with three strings in it,the length of each is 73. now see this program:
void main()
{
FILE *fp;
char Str[73];

fp=fopen("FilePath","r+b");
fread(Str,sizeof(char),73,fp);
fseek(fp,-73L,SEEK_CUR); //return to the beginning of FirstLine
fwrite(Str,sizeof(char),73,fp);
fread(Str,sizeof(char),73,fp); //fail
fread(Str,sizeof(char),73,fp); //fail
fclose(fp);
}
now, I've discovered that putting fseek(fp,ftell(fp),SEEK_SET)
after the fwrite solves the problem.
if anyone knows info that can be help,I will be glade to here.
thx,
gambit

and sorry for my bad english

Comments

  • : Hi, I'm writting a text editor in C, and I have a problem.
    : I isolated the problem to the next simple program:
    : first, I work with bin files,and when writting to the file or reading,
    : it's by Str[73].
    : suppose that we prepared a file with three strings in it,the length of each is 73. now see this program:
    : void main()
    : {
    : FILE *fp;
    : char Str[73];
    :
    : fp=fopen("FilePath","r+b");
    : fread(Str,sizeof(char),73,fp);
    : fseek(fp,-73L,SEEK_CUR); //return to the beginning of FirstLine
    : fwrite(Str,sizeof(char),73,fp);
    : fread(Str,sizeof(char),73,fp); //fail
    : fread(Str,sizeof(char),73,fp); //fail
    : fclose(fp);
    : }
    : now, I've discovered that putting fseek(fp,ftell(fp),SEEK_SET)
    : after the fwrite solves the problem.
    : if anyone knows info that can be help,I will be glade to here.

    An explicit call to either fseek() or fflush() is required between reads and writes in update ('+') mode. Read Question 12.30 in the C FAQ (second link in my signature) for more info.


    : thx,
    : gambit
    :
    : and sorry for my bad english

    Your English is fine! :)


    HTH,
    Will
    --
    http://www.tuxedo.org/~esr/faqs/smart-questions.html
    http://www.eskimo.com/~scs/C-faq/top.html
    http://www.parashift.com/c++-faq-lite/
    http://www.accu.org/


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion