Posted by Anonymous on Mon 21st Aug 20:43
download | new post
- void ordenar_peliculas()
- {
- int id=10001;
- int posicion=0;
- int i;
- FILE *archivo, *archivo2;
- char file1[20] = "peliculas.txt", file2[20] = "temporal.txt";
- Pelicula temp,temp2;
- archivo = fopen(file1,"r");
- archivo2 = fopen(file2,"a");
- while(!feof(archivo)){
- fread(&temp,sizeof(Pelicula),1,archivo);
- posicion++;
- }
- rewind(archivo);
- if(posicion>1){
- for(i=0;i<posicion;i++){
- while(!feof(archivo)){
- fread(&temp,sizeof(Pelicula),1,archivo);
- if (id>temp.id_pelicula){
- id = temp.id_pelicula;
- }
- }
- rewind(archivo);
- while (!feof(archivo)){
- fread(&temp,sizeof(Pelicula),1,archivo);
- if (id == temp.id_pelicula){
- fwrite(&temp,sizeof(Pelicula),1,archivo2);
- temp.id_pelicula=100001;
- }
- }
- }
- fclose(archivo);
- remove(file1);
- rename(file2,file2);
- }
- }
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.