On 2020-11-16, Harry Potter <
rose.joseph12@yahoo.com> wrote:
The following is the current code, and it _still_ gives me 0 bytes: -------------------------
fIn=fopen (argv[1], "rb");
fread(InBuffer, 1, 16*1024*1024, fIn);
vz.InEnd=ftell (fIn);
fclose (fIn); fIn=0;
printf ("Size: %d\n", vz.InEnd);
-------------------------
I'm not sure what to say. I wrote a test program that I compiled
both under gcc on Linux and Borland C++ Builder 5.5 on Windows XP.
When run with the command
foo foo.c
it displays the following lines:
fread() returned 857
ftell() returned 857
857 is the size in bytes of the source module, foo.c.
Under Linux it displays 816 rather than 857 because
Linux newlines are LF rather than CRLF. None of the
error checks in the code were triggered.
Here's the complete program:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv)
{
FILE *fp;
char *buf;
long templong;
int i;
if(argc != 2) {
printf("Usage: %s <filespec>\n", argv[0]);
exit(1);
}
fp = fopen(argv[1], "rb");
if(fp == NULL) {
printf("Can't open %s - errno = %d\n", argv[1], errno);
exit(1);
}
buf = malloc(16777216L);
if(buf == NULL) {
printf("malloc() failed - errno = %d\n", errno);
fclose(fp);
exit(1);
}
i = fread(buf, 1, 16777216L, fp);
if(i <= 0) {
printf("fread() returned %d - errno = %d\n", i, errno);
free(buf);
fclose(fp);
exit(1);
}
printf("fread() returned %d\n", i);
templong = ftell(fp);
printf("ftell() returned %ld\n", templong);
fclose(fp);
free(buf);
exit(0);
return(0);
}
--
/~\ Charlie Gibbs | "Some of you may die,
\ / <
cgibbs@kltpzyxm.invalid> | but it's sacrifice
X I'm really at ac.dekanfrus | I'm willing to make."
/ \ if you read it the right way. | -- Lord Farquaad (Shrek)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)