elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Problema con Pilas
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con Pilas  (Leído 1,566 veces)
jaxoR

Desconectado Desconectado

Mensajes: 93

?


Ver Perfil WWW
Problema con Pilas
« en: 5 Junio 2015, 19:50 pm »

Bueno, estoy haciendo un ejercicio para la facultad con pilas y secuencias (archivos de texto). El problema es que al pasar la pila a las funcionas para manejarla, me tira el siguiente error:

warning: passing argument 1 of 'pVacia' from incompatible pointer type [enabled by default]|
note: expected 'struct TPila *' but argument is of type 'struct TPila **'|
warning: passing argument 1 of 'pSacar' from incompatible pointer type [enabled by default]|
note: expected 'struct TPila *' but argument is of type 'struct TPila **'|
warning: passing argument 2 of 'pSacar' from incompatible pointer type [enabled by default]|
note: expected 'char *' but argument is of type 'char **'|
warning: passing argument 1 of 'pVacia' from incompatible pointer type [enabled by default]|
note: expected 'struct TPila *' but argument is of type 'struct TPila **'|
warning: passing argument 1 of 'sacarPila' from incompatible pointer type [enabled by default]|
note: expected 'char *' but argument is of type 'char **'|
warning: passing argument 3 of 'sacarPila' from incompatible pointer type [enabled by default]|
note: expected 'struct TPila *' but argument is of type 'struct TPila **'|
warning: passing argument 1 of 'pPoner' from incompatible pointer type [enabled by default]|
note: expected 'struct TPila *' but argument is of type 'struct TPila **'|
warning: passing argument 2 of 'pPoner' makes integer from pointer without a cast [enabled by default]|

Acá dejo el code y el header:

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "Pila.h"
  4.  
  5. #define MAX 50
  6.  
  7. void sacarPila(char *c, int n, TPila *p)
  8. {
  9.    int i = 0;
  10.  
  11.    while(!pVacia(&p) && i <= n)
  12.    {
  13.        pSacar(&p, &c);
  14.        i += 1;
  15.    }
  16.  
  17.    if(pVacia(&p))
  18.    {
  19.        printf("La pila esta vacia\n");
  20.    }
  21. }
  22.  
  23. void esDigito(char *c, TPila *p)
  24. {
  25.    int i = 10;
  26.  
  27.    switch(*c)
  28.    {
  29.        case '0': i = 0;
  30.        case '1': i = 1;
  31.        case '2': i = 2;
  32.        case '3': i = 3;
  33.        case '4': i = 4;
  34.        case '5': i = 5;
  35.        case '6': i = 6;
  36.        case '7': i = 7;
  37.        case '8': i = 8;
  38.        case '9': i = 9;
  39.    }
  40.  
  41.    if( i != 10)
  42.    {
  43.        sacarPila(&c, i, &p);
  44.    }
  45.    else
  46.    {
  47.        pPoner(&p, c);
  48.    }
  49. }
  50.  
  51. void vaciarPila(TPila *p)
  52. {
  53.    int i = 0;
  54.  
  55.    for(i=0; i<MAX; i++)
  56.    {
  57.        (*p).elem[i] = 0;
  58.    }
  59. }
  60.  
  61. int main()
  62. {
  63.    char c;
  64.    TPila p;
  65.    FILE *arch;
  66.    arch = fopen("secuencia.txt", "r");
  67.  
  68.    vaciarPila(&p);
  69.    if ( arch == NULL )
  70.   {
  71.   printf("- No se puede abrir el Archivo\n");
  72. return 0;
  73. }
  74.  
  75.    while((feof(arch) == 0) && !pLlena(&p))
  76.    {
  77.        c = fgetc(arch);
  78.        esDigito(&c, &p);
  79.    }
  80.  
  81.    while(!pLlena(&p))
  82.    {
  83.        pSacar(&p, &c);
  84.        printf("%c", c);
  85.    }
  86.    return 0;
  87. }

Código
  1. #include <stdlib.h>
  2. #include <stdbool.h>
  3.  
  4. #define MAX 50
  5.  
  6. typedef struct Pila
  7. {
  8.    int elem[MAX];
  9.    int cima;
  10. }TPila;
  11.  
  12. bool pVacia(TPila *p)
  13. {
  14.    return (*p).cima == 0;
  15. }
  16.  
  17. bool pLlena(TPila *p)
  18. {
  19.    return (*p).cima == MAX;
  20. }
  21.  
  22. void pCrear(TPila *p)
  23. {
  24.    (*p).cima = 0;
  25. }
  26.  
  27. void pPoner(TPila *p, char x)
  28. {
  29.    (*p).cima = (*p).cima + 1;
  30.    (*p).elem[(*p).cima] = x;
  31. }
  32.  
  33. void pSacar(TPila *p, char *c)
  34. {
  35.    *c = (*p).elem[(*p).cima];
  36.    (*p).cima = (*p).cima + 1;
  37. }


En línea

avesudra


Desconectado Desconectado

Mensajes: 724


Intentando ser mejor cada día :)


Ver Perfil
Re: Problema con Pilas
« Respuesta #1 en: 5 Junio 2015, 21:11 pm »

No estás pasando bien los parámetros a pSacar, pVacia y pPoner ya que reciben un puntero y le estás pasando un doble puntero al poner el ampersand, por ejemplo:
Código
  1. void sacarPila(char *c, int n, TPila *p)
  2. {
  3.    int i = 0;
  4.  
  5.    while(!pVacia(&p) && i <= n) //pVacia recibe un puntero, pero tu le pasas un doble puntero ya que le pones el ampersand a la p, que ya es un puntero.
  6.    {
  7.        pSacar(&p, &c); //Exactamente igual...
  8.        i += 1;
  9.    }
  10.  
  11.    if(pVacia(&p)) //Lo mismo
  12.    {
  13.        printf("La pila esta vacia\n");
  14.    }
  15. }
El código deberia quedar así:
Código
  1. void sacarPila(char *c, int n, TPila *p)
  2. {
  3.    int i = 0;
  4.  
  5.    while(!pVacia(p) && i <= n)
  6.    {
  7.        pSacar(p, &c);
  8.        i += 1;
  9.    }
  10.  
  11.    if(pVacia(p))
  12.    {
  13.        printf("La pila esta vacia\n");
  14.    }
  15. }


« Última modificación: 5 Junio 2015, 21:13 pm por avesudra » En línea

Regístrate en
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Pilas en c++
Programación C/C++
GABETORAP 1 1,916 Último mensaje 2 Diciembre 2011, 05:41 am
por [L]ord [R]NA
Problema Pilas y colas
Programación C/C++
Oppenheimer 0 2,796 Último mensaje 31 Octubre 2013, 23:26 pm
por Oppenheimer
Problema con Pilas en C
Programación C/C++
Xaan_rb 1 1,610 Último mensaje 25 Julio 2019, 02:58 am
por CalgaryCorpus
Problema con las pilas C++
Programación C/C++
98Fran 8 2,577 Último mensaje 31 Agosto 2019, 20:39 pm
por 98Fran
Problema fusionando pilas
Programación C/C++
DGP 2 2,395 Último mensaje 9 Marzo 2021, 06:57 am
por K-YreX
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines