STACK AND ITS APPLICATION
This program reverses every word in a multi-word string.Note the use of stack functions.
#include"stdio.h"
char *p;
char out();
main()
{
static char a,b;
int count=0,flag=0,run=0;
clrscr();
p=malloc(30*sizeof(char));
printf("enter the string:");
while(1)
{
while(a!=' ' && a!='\n')
{
scanf("%c",&a);
if(a!='\n')
in(a);
if(a=='\n')
flag=1;
count++;
}
if(run==0)
{
printf("target string:");
run=1;
}
while(count>0)
{
b=out();
if(flag==1)
printf(" ");
flag=0;
printf("%c",b);
count--;
}
if(a=='\n')
break;
in(' ');
a='~';
}
getch();
}
in(char t)
{
*p=t;
p++;
}
char out()
{
p--;
return *p;
}
Go back to the programs page click here!