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:
#include <stdio.h>
#include <stdlib.h>
#include "Pila.h"
#define MAX 50
void sacarPila(char *c, int n, TPila *p)
{
int i = 0;
while(!pVacia(&p) && i <= n)
{
pSacar(&p, &c);
i += 1;
}
if(pVacia(&p))
{
printf("La pila esta vacia\n");
}
}
void esDigito(char *c, TPila *p)
{
int i = 10;
switch(*c)
{
case '0': i = 0;
case '1': i = 1;
case '2': i = 2;
case '3': i = 3;
case '4': i = 4;
case '5': i = 5;
case '6': i = 6;
case '7': i = 7;
case '8': i = 8;
case '9': i = 9;
}
if( i != 10)
{
sacarPila(&c, i, &p);
}
else
{
pPoner(&p, c);
}
}
void vaciarPila(TPila *p)
{
int i = 0;
for(i=0; i<MAX; i++)
{
(*p).elem[i] = 0;
}
}
int main()
{
char c;
TPila p;
FILE *arch;
arch = fopen("secuencia.txt", "r");
vaciarPila(&p);
if ( arch == NULL )
{
printf("- No se puede abrir el Archivo\n");
return 0;
}
while((feof(arch) == 0) && !pLlena(&p))
{
c = fgetc(arch);
esDigito(&c, &p);
}
while(!pLlena(&p))
{
pSacar(&p, &c);
printf("%c", c);
}
return 0;
}
#include <stdlib.h>
#include <stdbool.h>
#define MAX 50
typedef struct Pila
{
int elem[MAX];
int cima;
}TPila;
bool pVacia(TPila *p)
{
return (*p).cima == 0;
}
bool pLlena(TPila *p)
{
return (*p).cima == MAX;
}
void pCrear(TPila *p)
{
(*p).cima = 0;
}
void pPoner(TPila *p, char x)
{
(*p).cima = (*p).cima + 1;
(*p).elem[(*p).cima] = x;
}
void pSacar(TPila *p, char *c)
{
*c = (*p).elem[(*p).cima];
(*p).cima = (*p).cima + 1;
}
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:
void sacarPila(char *c, int n, TPila *p)
{
int i = 0;
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.
{
pSacar(&p, &c); //Exactamente igual...
i += 1;
}
if(pVacia(&p)) //Lo mismo
{
printf("La pila esta vacia\n");
}
}
El código deberia quedar así:void sacarPila(char *c, int n, TPila *p)
{
int i = 0;
while(!pVacia(p) && i <= n)
{
pSacar(p, &c);
i += 1;
}
if(pVacia(p))
{
printf("La pila esta vacia\n");
}
}