/* * fileseek1.c - ftell(), fread(), fseek() */ #include #include int main(void) { FILE * fp; int count; float num; long position; if( (fp=fopen("numbers", "r+b")) == NULL ) { printf("fileseek1 cant open file numbers\n"); exit(1); } printf("This program moves the pointer\n"); printf("and reads the number at each location.\n\n"); position=ftell(fp); // takes file pointer, returns number of bites // address is the postiion in the file printf("After opening, position is: %d bytes", position); fread(&num, sizeof(float), 1, fp); printf("Value: %f\n\n", num); fseek(fp, 0, 1); // move pointer address 0 bites from its current location. position=ftell(fp); printf("After fseek(0,1), position is: %d bytes", position); fread(&num, sizeof(float), 1, fp); printf("Value: %f\n\n", num); fseek(fp, 0, 1); position=ftell(fp); printf("After fseek(0,1), position is: %d bytes", position); fread(&num, sizeof(float), 1, fp); printf("Value: %f\n\n", num); fseek(fp, 0, 1); position=ftell(fp); printf("After fseek(0,1), position is: %d bytes", position); fread(&num, sizeof(float), 1, fp); printf("Value: %f\n\n", num); //Later programs add more code here fclose(fp); return 0; }