Its a huge code
Code:
#include<string.h>
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
/*
* *********************************StackInit
* A new stack variable is initialized. The initialized
* stack is made empty.
* INPUT: stackP
* OUTPUT:void
*/
void StackInit(stackST *stackP)
{
stackElement *newContents;
/* Allocate a new array to hold the contents. */
newContents = (stackElement *)malloc(sizeof(stackElement) * 10);
stackP->contents = newContents;
stackP->lineST = 0;
stackP->top = -1; /* I.e., empty */
}
/*
* ******************************StackPush
* Add an element to the top of the stack
* INPUT: stackP. element and the line number where the tag was found
* OUTPUT:void
*
*/
void Push(stackST *stackP, stackElement element, int line)
{
/* Put information in array; update top. */
stackP->contents[++stackP->top] = element;
stackP->lineST=line;
}
/*
* ******************************StackPop
* Remove an element from the top of the stack.It first checks if the previous opening tag is closed,
* else it displays an error and recursively checks if the next opened tag has been closed.
* INPUT: stackP. element and the line number where the tag was found
* OUTPUT:void
*
*/
stackElement Pop(stackST *stackP, char *checkelement, int line)
{
if (strcmp(checkelement,stackP->contents)==0)
return stackP->contents[stackP->top--];
else
{
printf("\n Error: unmatched tag </%s>in line %d corresponding to line %d",checkelement,line,stackP->lineST);
stackP->top--;
return Pop(stackP,checkelement,line);
}
}