How it works...

First, a structure is defined, called a node, that consists of two members: one is the data and the other is a pointer called next. Because we want our stack to only store integer values, the data member of the structure is defined as an integer for storing integers and the next pointer is used to connect other nodes. Initially, the top pointer is set to NULL.

A while loop is set to execute, within which a menu is displayed. The menu is set to display three options: 1, to push into the stack; 2, to pop from the stack; and 3, to quit. Until the user enters 3 in the menu, the while loop will continue executing and keep displaying the menu, prompting the user to enter the desired option. If the user enters 1 to push a value to ...

Get Practical C Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.