Problem with system ("cls") and chains in C

0

I want to see if someone can help me, the problem is that my code collapses whenever it reads a cls and I'm driving strings, but I do not know what the solution might be or if the problem is elsewhere, try everything but it still does not work.

//Bibliotecas

#include <stdio.h>
#include <stdlib.h>

//Tipos
typedef struct nodo{
    int  iDias;
    struct nodo *liga;
} TpListaActividades;
typedef TpListaActividades *TapLiAct;

typedef struct Nodo {
    char cLetra;
    struct Nodo *siguiente;
} TipoNodo;
typedef TipoNodo *pSubCola;

typedef struct NodoPr {
    char Materia [20];
    int iPrioridad;
    struct NodoPr *siguiente;
    pSubCola iniciosub;
    pSubCola finalsub;
    TapLiAct Lista;
} TipoNodoPr;
typedef TipoNodoPr *pNodoPr;


//Prototipos
void AgregarPr (pNodoPr * , pNodoPr * , int *);
void ExtraerPr (pNodoPr * , pNodoPr * , int * );
void VerColaPr (pNodoPr inicio , pNodoPr final);
int SolicitudNum ();
char SolicitudCar ();

int main() {
    pNodoPr inicio = NULL , final = NULL , pAux;
    int iRes , iPrioridad = 0 , iExi;


     do {
        system("cls");
        printf("\nExisten %d materias registradas.\n" , iPrioridad);
        printf("\n1.- Agregar materia");
        printf("\n2.- Eliminar materia");
        printf("\n3.- Ver prioridades cola principal");
        printf("\n4.- Agregar sub-cola");
        printf("\n5.- Extraer sub-cola");
        printf("\n6.- Ver Colas");
        printf("\n0.- Salir");

        printf("\n\nIngresa la opcion deseada:  ");
        scanf("%d" , &iRes);

        switch (iRes) {

            case 1: {
                system("cls");
                printf("\n---------------------");
                printf("\nAgregar materias");
                printf("\n---------------------\n");

                printf("Ingrese el nombre de su materia: ");
                AgregarPr(&inicio , &final , &iPrioridad);

                fflush(stdin);
                getchar();
                break;}

            case 2: 
                system("cls");
                printf("\n---------------------");
                printf("\nEliminar materia");
                printf("\n---------------------\n");
                ExtraerPr(&inicio , &final , &iPrioridad);

                fflush(stdin);
                getchar();
                break;

            case 3: 
                system("cls");
                printf("\n---------------------");
                printf("\nVer materiass");
                printf("\n---------------------\n");
                VerColaPr(inicio , final);

                fflush(stdin);
                getchar();
                break;

            default : printf("Operacion no valida");
                break;


        }

    } while (iRes !=0);
    for (pAux = inicio->siguiente; pAux != NULL ; pAux = pAux->siguiente) {
        free(inicio);
        inicio = pAux;
        printf("\nExisten %d materias registradas.\n" , iPrioridad);
    }
}

void AgregarPr (pNodoPr *inicio , pNodoPr *final , int *iPrioridad) {

    pNodoPr nuevo;
    int iRes;

    nuevo = (pNodoPr ) malloc (sizeof (pNodoPr ));

    nuevo->iniciosub = NULL;
    nuevo->finalsub = NULL;
    nuevo->Lista = NULL;

    fflush(stdin);

    (*iPrioridad)++;
    fflush(stdin);
    scanf ("%[^\n]" , nuevo->Materia);

    if (*inicio == NULL && *final == NULL) {
        *inicio = nuevo;    //Inicio es nuevo por que es el primer elemento     

    } else {
        (*final) -> siguiente = nuevo;
    }

    nuevo -> siguiente = NULL;      //Aseguramos qeu el siguiente sea nulo ya que ahora este es el ultimo elemento
    nuevo->iPrioridad = *iPrioridad;        //Agregamos una nueva prioridad
    (*final) = nuevo;   //Final es nuevo por que es el ultimo elemento  


    printf("\nMateria %d creada satisfactoriamente." , *iPrioridad);
}

void ExtraerPr (pNodoPr *inicio , pNodoPr *final , int *iPrioridad) {
    pNodoPr pAux;

    switch (*iPrioridad) {

        case 0: {
            printf("\nNo existen prioridades que extraer, la cola esta vacia. %d" , *iPrioridad);
            break;}

        case 1: {
            *inicio = NULL;
            free (*final);      //Libero mi ex-ultimo elemento 
            *final = NULL;
            printf("\nLa ultima prioridad fue removida satisfactoriamente.");
            (*iPrioridad)--;
            break;}

        default :{
            for (pAux = *inicio; pAux->siguiente != *final  ; pAux = pAux->siguiente) {
            }
            free (*final);      //Libero mi ex-ultimo elemento 
            (*final) = pAux;    //Asigno mi nuevo ultimo elemento en final
            (*final)->siguiente = NULL;
            printf("\nLa prioridad %d fue removida satisfacoriamente" , *iPrioridad);
            (*iPrioridad)--;
            break;}
    }
}

void VerColaPr (pNodoPr inicio , pNodoPr final) {
    pNodoPr aux;

    if (inicio == NULL && final == NULL) {
        printf("\nLa cola esta vacia.");
    } else {

        for (aux = inicio ; aux != NULL ; aux = aux -> siguiente) {
            printf("\nMateria : %s" , aux->Materia);
            printf("\n\tPrioridad : %d" , aux->iPrioridad);
        }

    }
}
    
asked by esteban montoya 25.11.2018 в 17:17
source

0 answers