Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void guardarDatosAlumno(char nombref[], tAlumno p);
- int main()
- {
- guardarDatosAlumno(nombref, p);
- system("PAUSE");
- return0;
- }
- void guardarDatosAlumno(char nombref[], tAlumno p)
- {
- t alumno al;
- FILE*fich1;
- FILE*fich2;
- fich1 = fopen(nombref "rb");
- fich2 = fopen("auxiliar", "wb");
- if((fich1) = NULL) && (fich2 != NULL));
- {
- fread(&al, sizeof(alumno), 1, fich1);
- while((!fof(fich1)) && (stramp(al.dni, p.dni) < 0))
- {
- fwrite(&al, sizeof(talumno), 1, fich2);
- fread(&al, sizeof(talumno), 1, fich1);
- }
- fwrite(&p, sizeof(talumno), 1, fich2);
- while(!feof(fich1)
- {
- fwrite(&al, sizeof(al), 1, fich2);
- fread (&al, sizeof(al), 1, fich1);
- }
- fclose(fich1);
- fclose(fich2);
- }
- else
- {
- if(fich2 != NULL)
- {
- fwrite(&p, sizeof(p), 1, fich2);
- fclose(fich2);
- }
- remove(nombref);
- rename("auxiliar", nombref);
- }
- }
Add Comment
Please, Sign In to add comment