Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.11 KB | None | 0 0
  1. //By Diego
  2. //Si lo usan, porfa no copiar textual, gracias :D
  3.  
  4. #include<stdio.h>
  5. #include<string.h>
  6. #include<stdlib.h>
  7.  
  8. typedef struct{
  9.    char tema[20+1];
  10.    char categoria[30+1];
  11.    char album[30+1];
  12.    char interprete[30+1];
  13.    int cd;
  14. }cancion;
  15.  
  16. int OPCION(void){
  17.  
  18.    int choice;
  19.    do{
  20.       printf("| BIENVENIDO AL SISTEMA DE         |\n| ALMACENAMIENTO DE MUSICA PIRATA  |");
  21.       printf("\n|__________________________________|");
  22.       printf("\n\nElija una opcion:\n\n1.Almacenar Canciones\n2.Buscar Canciones\n3.Almacena Categorias\n4.Salir\n\nOPCION: ");
  23.       scanf("%d",&choice);
  24.    if(choice<1||choice>4){
  25.       printf("\n\nOpcion Incorrecta, Intente denuevo\n");
  26.       system("pause");
  27.       system("cls");
  28.     }
  29.   }while(choice<1||choice>4);
  30.       printf("%d",choice);
  31.       return choice;
  32. }
  33.  
  34. int main(){
  35.  
  36.    int N,i,a,b,choice;
  37.    char opcion[2+1],op[2+1];
  38.    cancion canciones;
  39.  
  40.    do{
  41.       switch(OPCION()){
  42.  
  43.          case 1:{
  44.                FILE *listado;
  45.                listado=fopen("Listado.dat","w+");
  46.                printf("\n\nNumero de canciones a ingresar: ");
  47.                scanf("%d",&N);
  48.                
  49.                if(listado == NULL){
  50.                   printf("Archivo Erroneo");
  51.                   return 0;
  52.                }
  53.  
  54.                 for(i=1;i<=N;i++){
  55.                   printf("\nTEMA%d: ",i);
  56.                   scanf("%s",canciones.tema);
  57.                   printf("\nCATEGORIA (rock/pop/clasicos): ");
  58.                   scanf("%s",canciones.categoria);
  59.                   printf("\nALBUM: ");
  60.                   scanf("%s",canciones.album);
  61.                   printf("\nINTERPRETE: ");
  62.                   scanf("%s",canciones.interprete);
  63.                   printf("\nNumero CD: ");
  64.                   scanf("%d",&canciones.cd);
  65.                   fwrite(&canciones, sizeof(cancion), 1, listado);
  66.                 }
  67.                 fclose(listado);
  68.          }break;
  69.  
  70.          case 2:{
  71.  
  72.                FILE *listado_lectura;
  73.                listado_lectura=fopen("Listado.dat","rb+");
  74.                rewind(listado_lectura);
  75.                
  76.                if(listado_lectura == NULL){
  77.                   printf("Archivo Erroneo");
  78.                   return 0;}
  79.  
  80.                char tema_aux[20+1];
  81.                do{
  82.                   printf("\n\nIngrese cancion a buscar: ");
  83.                   scanf("%s",tema_aux);
  84.                   while(fread(&canciones, sizeof(cancion), 1, listado_lectura)){
  85.                    
  86.                      if(!strcmp(tema_aux,canciones.tema))
  87.                         printf("Buscar en el cd: %d", canciones.cd);
  88.                      else
  89.                         printf("\nCancion no Encontrada");
  90.                   }
  91.                
  92.                rewind(listado_lectura);
  93.                printf("\n\nDesea buscar de nuevo (SI/NO): ");
  94.                scanf("%s",opcion);
  95.                a=!strcmp(opcion,"si");
  96.                b=!strcmp(opcion,"SI");
  97.  
  98.                }while(a||b);
  99.                fclose(listado_lectura);
  100.          }break;
  101.  
  102.          case 3:{
  103.  
  104.                FILE *pop,*rock,*clasicos,*listado;
  105.                listado=fopen("Listado.dat","rb+");
  106.                pop=fopen("pop.txt","w+");
  107.                rock=fopen("rock.txt","w+");
  108.                clasicos=fopen("clasicos.txt","w+");
  109.  
  110.                while(fread(&canciones,sizeof(cancion),1,listado)){
  111.                  if(!strcmp(canciones.categoria,"pop"))
  112.                      fwrite(&canciones,sizeof(cancion),1,pop);
  113.                  else if(!strcmp(canciones.categoria,"rock"))
  114.                      fwrite(&canciones,sizeof(cancion),1,rock);
  115.                  else if(!strcmp(canciones.categoria,"clasicos"))
  116.                      fwrite(&canciones,sizeof(cancion),1,clasicos);
  117.                }
  118.  
  119.                fclose(listado);
  120.  
  121.             }break;
  122.  
  123.             case 4:{
  124.                printf("\n\nADIOS");
  125.                return 0;
  126.                }break;
  127.  
  128.    }
  129.    printf("\nDesea Seguir usando el programa (SI/NO): ");
  130.    scanf("%s",op);
  131.    system("cls");
  132.    }while(!strcmp(op,"si")||!strcmp(op,"SI"));
  133.  
  134.    printf("\nADIOS");
  135.    return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement