AllExperts > C 
Search      
C
Volunteer
Answers to thousands of questions
 Home · More C Questions · Answer Library  · Encyclopedia ·
More C Answers
Question Library

Ask a question about C
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Prince M. Premnath
Expertise

I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience
Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

 
   

You are here:  Experts > Computing/Technology > C/C++ > C > Reverses string contents using stack in C

C - Reverses string contents using stack in C


Expert: Prince M. Premnath - 10/26/2009

Question
May i know how to write C programming using stack for reverses string using stack (the top and bottom elements exchange positions, the second last element exchange positions, and so forth until the entire stack is reversed). And how to use 2nd stack?

Answer
Hi dear mazlee!

Need not to go for that much heavy processing ,say reversing , swapping kinda things
just have a look at this simple program , uses stack to reverse the sentence


#include<stdio.h>
#include<conio.h>
#define MAX_STK 200

void main()
{
  int i = -1;
  int Counter = 0;
  char Stack[MAX_STK];
  char* srcString = "this is a text string";
  char* temp = srcString;

  while(*srcString)
     Stack[++i] = *srcString++;
  Counter = i;
  while(Counter >= 0)
     printf("%c",Stack[Counter--]);
  getch();
}

Note: Get back to me in case of issues

Thanks and Regards
Prince M. Premnath

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.