27)Write a C program to accept a string and Reverse a each word of string using static Implementation of Stack.


#include<stdio.h>
#include<conio.h>
#define MAX 50
char a[MAX];
int top=-1;
void push(char c)
{
top++;
a[top]=c;
}
char pop()
{
char c;
c=a[top];
top–;
return c;
}
void main()
{
int i;
clrscr();
printf(“\n\nENTER THE STRING”);
gets(a);
for(i=0;a[i]!=”; i++)
{
if(a[i]==’ ‘)
{
while(top!=-1)
{
printf(“%c”,pop());
}
printf(” “);
}
else
{
if(top==MAX-1)
{
printf(“\n\nSTACK IS FULL”);
}
else
{
push(a[i]);
}
}
}
while(top!=-1)
{
printf(“%c”,pop());
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s