0
... rewind(ftmpname); if (stat(tmpname, &st_file)==-1) longjmp(Berror, (ETMPSTAT) ); tmpsize = st_file.st_size; i = 0; while (i<tmpsize) { n = fread(buf, 1, (READ_CONST), ftmpname ); write_byte(farch, buf, n); i+=n; } ... 

fread always returns 0. I don't know what's wrong. I do a rewind before, and it didn't help. Sorry for my English.

3
  • How are you opening ftmpname and what are you doing with it before getting to this code? Commented Mar 12, 2012 at 17:56
  • ftmpname = fopen(tmpname, "wb"); then i use function which accepts ftmpname and reads info from ftmpname twice; Commented Mar 12, 2012 at 18:01
  • Are you writing the file without closing and re-opening it? It sounds like you are, which might explain why it's not going very well. You must have the file open for reading in order to read, I guess that's obvious but it seems you're missing out on it. Commented Mar 12, 2012 at 18:02

1 Answer 1

2

If you don't know what is wrong, you have to check for errors. Here is what a manual page says:

RETURN VALUE

fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero).

fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred.

So why don't you use those functions which tell you exactly what is wrong?

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I'll try. And one more question: function stat() returns 0 but st_file.st_sizes = 0. Why? Did I do smth wrong?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.