c programming using stack

youssefgameplay

Registered Member
Joined
Mar 15, 2018
Messages
62
Reaction score
3
hey guys i want to create a c program to read a sentence and reverse it using stack but its kinda hard i dont know how to read or print a stack if anyone can help thanks
 
use recursion to reverse the string.

Code:
#include <stdio.h>

void reverseString (const char * s) {
  if (*s) {
    reverseString(s + 1);
    fprintf(stdout, "%c", s[0]);
  }
}

int main (int argc, char ** argv) {
  reverseString("G4143 can you reverse this?");
  fputs("\n", stdout);
  reverseString("How about this?");
  fputs("\n", stdout);
  return 0;
}
 
Last edited:
use recursion to reverse the string.

Code:
#include <stdio.h>

void reverseString (const char * s) {
  if (*s) {
    reverseString(s + 1);
    fprintf(stdout, "%c", s[0]);
  }
}

int main (int argc, char ** argv) {
  reverseString("G4143 can you reverse this?");
  fputs("\n", stdout);
  reverseString("How about this?");
  fputs("\n", stdout);
  return 0;
}
You didn't you stack *******
 
Back
Top