Imran wrote:
[...]
FILE *fp = fopen(pTempFileLocation,"r+t");
//This Code is to find the size of the file
//simplest way
fseek(fp,0L,SEEK_END);
//now file poitner in the last poisition.
//so pos will have the size :)
long pos = ftell(fp);
[...]
Well, ignoring the fact that you appear to have C++ code, and not C, my
understanding is that on a text file (as noted by your "r+t" on fopen),
the number of bytes gotten with fread() is not necessarily the same as
the poisition of EOF. (In fact, under DOS/Windows, you are virtually
guaranteed that fread will get less bytes than your fseek/ftell combo
tells you are there.) This is because end-of-line will be returned as
a single '\n' character even though it may be stored on disk as more
than a single byte.
For example, a text file on Windows containing a single line of the
word "foobar" will contain 8 or 9 bytes according to fstat or the
fseek/ftell combo.
It will either be:
66 6f 6f 62 61 72 0d 0a
or
66 6f 6f 62 61 72 0d 0a 1a
In either case, fread will only get 7 characters:
66 6f 6f 62 61 72 0a
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody |
www.hvcomputer.com | |
| kenbrody/at\spamcop.net |
www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+