#include typedef struct { int clave; char datos[20]; } TIPOREG; void CrearFichero( void ) { FILE *fp; TIPOREG treg [5] = { {2001,"MADRID"}, {2002,"SEVILLA"}, {2005,"MURCIA"}, {2006,"AVILA"}, {2020,"BILBAO"} }; fp = fopen("DATOS.DAT","wb"); fwrite(treg ,sizeof(TIPOREG),5,fp); fclose(fp); } void main() { FILE *fp; TIPOREG reg; CrearFichero(); fp = fopen ("DATOS.DAT","rb"); // Leo el primer registro fread(®,sizeof(reg),1, fp ); printf("A) %d, %s \n",reg.clave, reg.datos ); printf("Posición = %d \n", ftell(fp)/sizeof(reg)); // Me posiciones en el penultimo fseek(fp,-2L * sizeof(reg), SEEK_END); fread(®,sizeof(reg),1, fp ); printf("B) %d, %s \n",reg.clave, reg.datos ); printf("Posición = %d \n", ftell(fp)/sizeof(reg)); // Me muevo dos posiciones hacia atras fseek(fp,-2L * sizeof(reg), SEEK_CUR); fread(®,sizeof(reg),1, fp ); printf("C) %d, %s \n",reg.clave, reg.datos ); printf("Posición = %d \n", ftell(fp)/sizeof(reg)); // Me situo despues del primero fseek(fp,1L * sizeof(reg) ,SEEK_SET); fread(®,sizeof(reg),1, fp ); printf("D) %d, %s \n",reg.clave, reg.datos ); printf("Posición = %d \n", ftell(fp)/sizeof(reg)); fclose(fp); getchar(); }