#include <stdio.h>
#include <stdlib.h>
int copy (int *hd, int *ram){
    int nprocam,i;
        printf("\nNumero do processo que deseja mover para memoria secundaria:");
        scanf("%d", &nprocram);
            if(nprocram <1 || nprocram >5){printf("processo nao existe\n\n");}
            for (i=1; i<6; i++){
                if (hd[i] == 0){
                    hd[i] = ram[nprocram];
                    ram[nprocram] = 0;
                }


            }


int main(){
	int ni;
	int *hd;
	int *ram;
	int i,opcao,nprocram,nprochd;

	hd = (int*) malloc (5* sizeof(int));
    ram = (int*) malloc (5* sizeof(int));


    for (i=1; i<6; i++){
        hd[i]=0;
        ram[i]=0;
    }

	while(opcao != 8 ){

	    printf("\t\t\t\tMENU");
        printf("\n1. limpar memoria principal                      2. limpar memoria secundaria");
        printf("\n3. alocar um processo na memoria principal       4. swap out");
        printf("\n5. swap in                                       6. listar memoria principal");
        printf("\n7. listar memoria secundaria                     8. sair\n");
        printf("\n\nEscolha uma opcao:");
        scanf("%d", &opcao);
        system("cls");

        if (opcao==1){
    	    for (i=1; i<6; i++){
    		    ram[i] = 0;
            }
        }
	    if (opcao==2){
    	    for (i=1; i<6; i++){
    		    hd[i] = 0;
		    }
	    }
	    if (opcao==3){
		    for(i=1; i<6; i++){
			    scanf("%d",&ram[i]);
		    }
	    }
        if (opcao==4){

                int xx,yy;
                copy (hd,ram);
        }
        if (opcao==5){printf("\nNumero do processo que deseja voltar para a memoria principal:");
            scanf("%d", &nprochd);
            if(nprochd<1 || nprochd >5){printf("processo nao existe\n\n");}
            for (i=1; i<6; i++){
                if(ram[i]==0){
                    ram[i] = hd[nprochd];
                    hd[nprochd] = 0;
                }
            }
        }
        if (opcao == 6){printf("memoria principal\n");
            for(i=1; i<6; i++){
                printf("\nRAM: - %d", ram[i]);
            }
        }
        if (opcao == 7){printf("memoria secundaria\n");
            for(i=1; i<6; i++){
                printf("\nRAM: - %d", hd[i]);
            }
        }

    }
}
