youssefgameplay
Registered Member
- Mar 15, 2018
- 62
- 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
#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 *******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; }