/* Escribe registros en el fichero ALUMNOS.DAT */ #include #include #include typedef struct { char nombre[30]; int edad; int curso; int nota; } TIPOALUMNO; void MostrarCabeceras (void) { gotoxy(1, 8); puts("---------------------------------------------"); puts(" DATOS ALUMNO "); puts("---------------------------------------------"); puts(" NOMBRE :"); puts(" EDAD :"); puts(" CURSO :"); puts(" NOTA :"); puts("---------------------------------------------"); } void MostrarCampos (TIPOALUMNO reg) { /* Borro los textos anteriores */ gotoxy(15, 11); puts(" "); gotoxy(15, 12); puts(" "); gotoxy(15, 13); puts(" "); gotoxy(15, 14); puts(" "); /* Muestro los nuevos valores */ gotoxy(15, 11); puts(reg.nombre); gotoxy(15, 12); printf("%d",reg.edad); gotoxy(15, 13); printf("%d",reg.curso); gotoxy(15, 14); printf("%d",reg.nota); } main () { FILE *fent; TIPOALUMNO ralumno; char continuar; fent = fopen("ALUMNOS.DAT","rb"); if ( fent == NULL ) { perror("ALUMNOS.DAT"); exit(1); } clrscr(); // Borro la pantalla MostrarCabeceras(); continuar = 's'; fread(&ralumno,sizeof(TIPOALUMNO),1,fent ); while ( toupper(continuar) == 'S' && !feof(fent) ) { MostrarCampos(ralumno); fread(&ralumno,sizeof(TIPOALUMNO),1,fent ); gotoxy(20,16); printf( "Siguiente (s/n):"); continuar = getch(); gotoxy(20,16); printf( " "); } if ( feof(fent) ) puts ("\n "); getchar(); fclose(fent); }