Files
2023-04-10 00:19:18 +00:00

33 lines
770 B
C

/*
COS135 - HW9c
Nicholas Pease
Reverse String
*/
#include <stdio.h>
#include <string.h>
#include "PEASE.h"
int main() {
// Input string
printf("Reverse a phrase: ");
char input[20];
fgets(input,20,stdin);
// Strip newline
for (int i=0;i<strlen(input);i++) if (input[i] == '\n') input[i] = '\0';
// Start String Reversal, reversal string only has to be as long as the input string
char reverse[strlen(input)];
// Two Loops, one to throw in the stack....
for (int i = 0; i < strlen(input); i++) {
push(input[i]);
}
// ... one to yank it back out again
for (int i = 0; i < strlen(input); i++) {
reverse[i] = pop();
}
printf("Reversed output is \"%s\"\n",reverse);
return 0;
}