Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct{
- int dni;
- char apellido [21];
- char nombre [21];
- float prom;
- }t_estudiantes;
- int main()
- {
- FILE *fp, *ft;
- int r;
- t_estudiantes est[]={{41222222, "Lencinas", "Alejo", 8.00},
- {4231523, "Bentivenga", "Simon", 9.00},
- {42315723, "Trillini", "Lucas", 5.00},
- {741236598, "Sol", "Federico", 8.75},
- {21346975, "Juan", "Lautaro", 8.95},
- {32156498, "Ruiz Diaz", "Manuel", 7.00},
- {2136548, "Klehr", "Brian", 4.00}};
- fp=fopen("Estudiantestexto.dat", "w");
- for(int i=0; i<7;i++){
- fprintf(fp, "%08d%-20s%-20s%05.2f\n", est[i].dni, est[i].apellido, est[i].nombre, est[i].prom);}
- fclose(fp);
- ft=fopen("EstudiantesBinario.dat", "wb");
- fp=fopen("Estudiantestexto.dat", "r");
- t_estudiantes ests;
- r=fscanf(fp,"%8d%20[^\n]%20[^\n]%5f\n", &ests.dni, &ests.apellido, &ests.nombre, &ests.prom );
- while (!feof(fp)&&r==4){
- fwrite(&ests, sizeof(t_estudiantes), 1, ft);
- r=fscanf(fp, "%8d%20[^\n]%20[^\n]%5f\n", &ests.dni, &ests.apellido, &ests.nombre, &ests.prom );
- }
- fclose(fp);
- fclose(ft);
- ft=fopen("EstudiantesBinario.dat", "rb");
- fread(&ests,sizeof(t_estudiantes), 1, ft);
- while(!feof(ft)){
- printf("%d %s %s %.2f\n", ests.dni, ests.apellido, ests.nombre, ests.prom);
- fread(&ests,sizeof(t_estudiantes), 1, ft);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement