#define StackLimit 50   // ôï üñéï ìåãÝèïõò ôçò óôïßâáò, åíäåéêôéêÜ ßóï ìå 50
#include <stdio.h>

typedef int StackElementType;   // ï ôýðïò ôùí óôïé÷åßùí  ôçò óôïßâáò                                //åíäåéêôéêÜ ôýðïò int 
typedef struct  {
    int Top;
    StackElementType Element[StackLimit];
} StackType;

typedef enum {
    FALSE, TRUE
} boolean;

void TraverseStack(StackType Stack);
void CreateStack(StackType *Stack);
boolean FullStack(StackType Stack);
void Push(StackType *Stack, StackElementType Item,int *k);
void FilterStack(StackType *Stack,StackElementType Item);



main()
{
   StackType Stack;
   int k,i,Item;

   char choice;


printf("Dimiourgia stoibas.....Please wait...\n");
CreateStack(&Stack);  
printf("Dwse ta stoixeia ths stoibas : \n");
do{
    i=0;
    printf("Give the  %d item :",i);
    printf("\n");
    scanf("%d",&Item);
    i++;
Push(&Stack,&Item,&k);
    printf("Do you want to exit from the loop ???  y/n ?: ");
    scanf("%c",&choice);
    printf("\n");
    if((choice=='y')||(choice=='Y')) break;

   while}(k!=0);
printf("H Stoiba einai h parakatw:\n");
TraverseStack(Stack);


printf("Dwse to stoixeio DIAGRAFHS : ");
scanf("%d",&Item);    
FilterStack(&Stack,Item);    

TraverseStack(Stack);    



system("pause");    
}

void TraverseStack(StackType Stack)
{
    int i;
    printf("\nPlithos Stoixeiwn Sthn Stoiba %d\n",Stack.Top+1);
    for (i=0;i<Stack.Top;i++)
        printf("%d, ",Stack.Element[i]);

    printf("\n");
}



void FilterStack(StackType *Stack,StackElementType Item)
{
    StackElementType j;
    StackType TempStack;

    TempStack.Top=(*Stack).Top;
    for(j=0;j<(*Stack).Top;j++)
    {
        if((*Stack).Element[j]!=Item)
        {
            TempStack.Element[j]=(*Stack).Element[j];
        }
        else
        {
         printf("To stoixeio BRETHIKE !! \n");
         TempStack.Top--;   
        }
    }

    for(j=0;j<TempStack.Top;j++)
      {
            (*Stack).Top=TempStack.Top;
            (*Stack).Element[j]= TempStack.Element[j];
      }



}

void Push(StackType *Stack, StackElementType Item,int *k) 
{
    *k=1;
    if (!FullStack(*Stack)) {
        (*Stack).Top++;
        (*Stack).Element[(*Stack).Top]=Item;


    } else
        printf("Full Stack...");
        *k=0;
}


void CreateStack(StackType *Stack) 
{
    (*Stack).Top=-1;

}

When i try to compile i got those warnings you can see in the image i've uploaded:

My second question is this:
Why i need to pass as struct as a pointer ? In other codes i wrote i used to pass struct arguments like matrix.
For example if i had-->

typedef struct 
{
char CarName[100];
int  Number;

}domiT;





domitT stx[10];

The only thing i had to do for passing arguments into a void function was to type:

void NameOfFunction (domiT stx[]) 

Now instead of this i have to type :

void NameOfFunction  (StackType *Stack);

Is that because StackType Stack is not a matrix ? Because its not sth like StackType Stack[100] ???????

mmmm

Thank you for supporting me all that time :-)

First, you declare Push() with this signature: void Push(StackType *Stack, StackElementType Item,int *k);
yet you call it like this: Push(&Stack,&Item,&k);
Do you see the problem? It would work if you called it like this: Push(&Stack,Item,&k);

As for the rest, read the error/warning messages - they pretty much tell you what is wrong. An important part of programming is being able to decipher compiler errors and warning messages so you can correct your program.

Edited 3 Years Ago by rubberman

This question has already been answered. Start a new discussion instead.