ftell

End of FILE* pointer is not equal to size of written data.

Very simply put, I have the following code snippet: FILE* test = fopen("C:\\core.u", "w"); printf("Filepointer at: %d\n", ftell(test)); fwrite(data, size, 1, test); printf("Written: %d bytes.\n", size); fseek(test, 0, SEEK_END); printf("Filepointer is now at %d.\n", ftell(test)); fclose(test); and it outputs: Filepointer at: 0 Writte...

Why is fwrite writing more than I tell it to?

FILE *out=fopen64("text.txt","w+"); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf("%i\n",ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf("%i\n",write); printf("%i\n",ftello64(out)); output: 0 25755 25868 what is going on? write is set to 25755, and I tell fwrite to write that many bytes to a fi...

ftell( stdin ) causes illegal seek error

The following code outputs "Illegal seek": #include <stdio.h> #include <errno.h> #include <string.h> int main() { errno = 0; getchar(); getchar(); getchar(); ftell( stdin ); printf( "%s\n", strerror(errno) ); } This occurs when I run "cat script | ./a.out" as well as when I just run "./a.out". The problem is...

ftell error after the first call to fread

So I have a very simple program that reads the 3 first bytes of a file: int main(void) { FILE *fd = NULL; int i; unsigned char test = 0; fd = fopen("test.bmp", "r"); printf("position: %ld\n", ftell(fd)); for (i=0; i<3; i++) { fread( printf("position: %ld char:%X\n", ftell(fd), test); } ...

ftell on a file descriptor?

Is there a way to do what ftell() does (return the current position in the file) on a raw file descriptor instead of a FILE*? I think there ought to be, since you can seek on a raw file descriptor using lseek(). I know I could use fdopen() to create a FILE* corresponding to the file descriptor, but I'd rather not do that. ...