/* * Copyright 2026 Amber Hu and Justin Hsia * Ask user for a word and print it forwards and backwards. * CSE 333 demo (for debugging) */ #define MAX_STR 100 /* length of longest input string */ #include #include #include /* Return a new string with the contents of s backwards */ char* Reverse(char* s) { char* result = NULL; /* the reversed string */ int left_i, right_i; char ch; /* copy original string then reverse and return the copy */ strcpy(result, s); left_i = 0; right_i = strlen(result); while (left_i < right_i) { ch = result[left_i]; result[left_i] = result[right_i]; result[right_i] = ch; ++left_i; --right_i; } return result; } /* Ask the user for a string, then print it forwards and backwards. */ int main() { char line[MAX_STR]; /* original input line */ char* rev_line; /* backwards copy from reverse function */ printf("Please enter a string: "); fgets(line, MAX_STR, stdin); rev_line = Reverse(line); printf("The original string was: >%s<\n", line); printf("Backwards, that string is: >%s<\n", rev_line); printf("Thank you for trying our program.\n"); return EXIT_SUCCESS; }