B
Bill Cunningham
This seems like a simple enough question that it shouldn't be too difficultin clc discussion. If the discussion would turn to learning or teaching. Iwant to allocate enough memory to hold a whole file. malloc is of course going to be needed so I think fseek is the way to learn how big a file is. Itried this and the code compiled find and displayed nothing so I'm at a loss as to what happened. I deleted the source code so I will make referencesto it.
#include <stdio.h>
FILE *fp;
if ((fp=fopen("j","rb"))==NULL)
perror("fopen 1 error");
long l;
while(!feof(fp))
l=fseek(fp,0,SEEK_SET);
fclose(fp);
printf("%d\n%d\n",l,ftell(fp));
}
This compiles fine and prints nothing. Did the file pointer move? Or is there a problem with printf?
Bill
#include <stdio.h>
FILE *fp;
if ((fp=fopen("j","rb"))==NULL)
perror("fopen 1 error");
long l;
while(!feof(fp))
l=fseek(fp,0,SEEK_SET);
fclose(fp);
printf("%d\n%d\n",l,ftell(fp));
}
This compiles fine and prints nothing. Did the file pointer move? Or is there a problem with printf?
Bill