/Stacks

Primary LanguageC

Stacks

Write a C program named exerciseStackthat takes a single command-line argument, which is a filename. This input file contains instructions for stack operations. The first line of the input file is an integer 0≤𝑁𝑁≤105 giving the number of instructions that will follow. Each of the following 𝑁𝑁 lines contains an instruction. The possible instructions are:•push X: where −109≤𝑋𝑋≤109 is a long integer. Upon receiving this instruction, push 𝑋𝑋 onto the stack. There is no output from this instruction.•pop: pop the top element from the stack. Print the removed element on a line by itself. If the stack was empty, print StackError.•print: print the contents of the stack, with each pair of elements separated by a single space, starting at the top (the element that would be removed by a pop). If the stack is empty, print Empty. The stack must be in the same state after it has been printed as it was before it was printed.You must use the generic Stack ADT described in section 7.2 of the textbook. You will have to write a function to implement the print action since it is not a method in the ADT. This function should satisfy the following signature void printStack(const Stack *st, FILE *fp);it prints the stack contents on fp, and accomplishes this task using only the methods on the Stack ADT. Note that you MAY NOT use the toArray()or itCreate()methods in your printStack()implementation. You may, of course, use other aspects of C in the implementation of this function.All output must be to standard output. Each line of output must be terminated by a newline character.