Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void guardarDatosAlumno(char nombref[], tAlumno p);
  6.  
  7. int main()
  8. {
  9.  
  10. guardarDatosAlumno(nombref, p);
  11.  
  12. system("PAUSE");
  13. return0;
  14.  
  15. }
  16.  
  17.  
  18. void guardarDatosAlumno(char nombref[], tAlumno p)
  19. {
  20. t alumno al;
  21. FILE*fich1;
  22. FILE*fich2;
  23.  
  24. fich1 = fopen(nombref "rb");
  25. fich2 = fopen("auxiliar", "wb");
  26.  
  27. if((fich1) = NULL) && (fich2 != NULL));
  28. {
  29. fread(&al, sizeof(alumno), 1, fich1);
  30. while((!fof(fich1)) && (stramp(al.dni, p.dni) < 0))
  31. {
  32. fwrite(&al, sizeof(talumno), 1, fich2);
  33. fread(&al, sizeof(talumno), 1, fich1);
  34. }
  35.  
  36. fwrite(&p, sizeof(talumno), 1, fich2);
  37. while(!feof(fich1)
  38. {
  39. fwrite(&al, sizeof(al), 1, fich2);
  40. fread (&al, sizeof(al), 1, fich1);
  41. }
  42.  
  43. fclose(fich1);
  44. fclose(fich2);
  45.  
  46. }
  47. else
  48. {
  49. if(fich2 != NULL)
  50. {
  51. fwrite(&p, sizeof(p), 1, fich2);
  52. fclose(fich2);
  53. }
  54.  
  55. remove(nombref);
  56. rename("auxiliar", nombref);
  57. }
  58. }
Add Comment
Please, Sign In to add comment