NEWS: Total Picture Views: 151536 | Total Article Views: 161033 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. PickUpThings with Becker Robot | 3. How to read a JSON and work with it | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

General Stack C

Description:

In this example I will be showing you how to use a general stack.

Code:

// in this excercise we put all functions of stack
// into a header file named stack.h to be used as a library
// Stack.h should be stored under the include folder of the IDE
// we will use a stack to reverse the order of input characters
#include<stdio.h>
#include <stack.h>

// define a generic data type named StackData 
// all functions in stack.h uses this data type.
typedef struct{
	char ch;
}StackData;

// include the library stack.h


int main(){
	// declare temporary variables for getting data from user
	StackData temp; 
	char c;

	// create an ampty stack
	Stack s=initStack();

	// display a message to show the type of data to be entered
	printf("enter a set of letters and press enter \n");

	// getting a char by char till the enter is pressed
	while((c=getchar())!='\n'){
		// store the character into the generic data structure
		temp.ch=c;

		// insert the temp data structure into the stack
		push(s,temp);
	}

	printf(" the characters in the reverse order \n"); 
	while(!empty(s))
		putchar(pop(s).ch);
	putchar('\n');
}

  
Attachments: None

Tags: General Stack

Total Views: 808

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 02/27/15


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.