...
The code was compiled with Microsoft Visual Studio 2008 SP1 on Windows XP Professional SP4SP3:
| Code Block |
|---|
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
char a[11];
long offset;
/* The contents of foo.txt are: 0123456789 repeated 10 times separated by line feeds (ie \n) */
fp = fopen( "foo.txt", "r" );
if (fp == NULL) {
perror("fopen() error");
exit(EXIT_FAILURE);
}
/* Read 10 (n-1) bytes */
if (fgets(a, 11, fp) == NULL) {
perror("fgets() error");
fclose(fp);
exit(EXIT_FAILURE);
}
offset = ftell(fp);
if (offset == -1) {
perror("ftell() error");
fclose(fp);
exit(EXIT_FAILURE);
}
printf("offset = %ld\n", offset); /* Prints out 0.*/
return 0;
}
|
...