Advertisement
nahuelbkn

No muestra los datos ingresados

Jun 30th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define arAlumno "archivoAlumnos.dat"
  5.  
  6.  
  7. typedef struct
  8. {
  9.     int legajo;
  10.     char nombre[30];
  11.     int documento;
  12.     int edad;
  13.     char domicilio[30];
  14.     char carrera[30];
  15. } stDatosPersonales;
  16.  
  17. void cargarAlumno(int *ultimoLegajo);
  18. void mostrarAlumno();
  19.  
  20. int main()
  21. {
  22.     int legajos = 0;
  23.  
  24.     ///cargarAlumno(&legajos);
  25.     mostrarAlumno();
  26.  
  27.  
  28.  
  29.  
  30.     return 0;
  31. }
  32.  
  33. void cargarAlumno(int *ultimoLegajo)
  34. {
  35.  
  36.     char control;
  37.     FILE *pArchivo;
  38.     stDatosPersonales datos;
  39.  
  40.     pArchivo = fopen(arAlumno, "ab");
  41.     if(pArchivo != NULL)
  42.     {
  43.         do
  44.         {
  45.             datos.legajo = ultimoLegajo + 1;
  46.             printf("\nNombre: ");
  47.             fflush(stdin);
  48.             scanf("%s", &datos.nombre);
  49.             printf("\nDocumento: ");
  50.             fflush(stdin);
  51.             scanf("%i", &datos.documento);
  52.             printf("\nEdad: ");
  53.             fflush(stdin);
  54.             scanf("%i", &datos.edad);
  55.             printf("\nDomicilio: ");
  56.             fflush(stdin);
  57.             scanf("%s", &datos.domicilio);
  58.             printf("\nCarrera: ");
  59.             fflush(stdin);
  60.             scanf("%s", &datos.carrera);
  61.  
  62.             fwrite(&datos, sizeof(stDatosPersonales), 1, pArchivo);
  63.             ultimoLegajo += 1;
  64.  
  65.  
  66.             printf("Desea ingresar mas datos? (S/N)..: ");
  67.             fflush(stdin);
  68.             scanf("%c", &control);
  69.             control = toupper(control);
  70.         }
  71.         while(control == 'S');
  72.  
  73.         fclose(pArchivo);
  74.     }
  75.     else
  76.         printf("\n\n\tSE PRODUJO UN ERROR.\n\n");
  77. }
  78.  
  79. void mostrarAlumno()
  80. {
  81.     FILE *pArchivo;
  82.     stDatosPersonales datos;
  83.  
  84.     pArchivo = fopen(arAlumno, "rb");
  85.     if(pArchivo != NULL)
  86.     {
  87.         while(fread(&datos, sizeof(stDatosPersonales), 1, pArchivo) > 0)
  88.         {
  89.             printf("\n--------------------------------------\n");
  90.             printf("Legajo: ", datos.legajo);
  91.             printf("\nNombre: ", datos.nombre);
  92.             printf("\nDocumento: ",datos.edad);
  93.             printf("\nEdad: ", datos.edad);
  94.             printf("\nDomicilio: ", datos.domicilio);
  95.             printf("\nCarrera: ", datos.carrera);
  96.             printf("\n--------------------------------------");
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement