fork download
  1. //Andrew Alspaugh CS1A Chapter 10. P. 588. #1
  2. //
  3. /****************************************************************************
  4. Reverse Characters of String
  5. ____________________________________________________________________________
  6. This program displays a user inputted string, and then it displays the
  7. characters of the string in reverse order
  8. ____________________________________________________________________________
  9. //Input
  10. int SIZE = 101;
  11. char strIN [SIZE];
  12.  
  13. //Output
  14. int length; (length of string)
  15. char strOUT [SIZE];
  16.  
  17. ****************************************************************************/
  18.  
  19. #include <iostream>
  20. #include <cstring>
  21. using namespace std;
  22.  
  23. //Reverse Characters Header
  24. void ReverseChar(const char *strIN, char *strOUT, int &length);
  25.  
  26. int main()
  27. {
  28. //DATA DICTIONARY
  29. //Input
  30. int SIZE = 101;
  31. char strIN [SIZE];
  32.  
  33. //Output
  34. int length;
  35. char strOUT [SIZE];
  36.  
  37. //INPUT
  38. //Input String
  39. cin.getline (strIN, SIZE);
  40.  
  41. //PROCESS
  42. //Reverse String
  43. ReverseChar(strIN, strOUT, length);
  44.  
  45. //OUTOUT
  46. //User Input String
  47. cout << "User Inputted:" << endl;
  48. cout << strIN << endl << endl;
  49.  
  50. //Reverse String
  51. cout << "Reverse String is:" << endl;
  52. cout << strOUT << endl;
  53.  
  54. return 0;
  55. }
  56.  
  57. //Reverse Character Def
  58. void ReverseChar(const char *strIN, char *strOUT, int &length)
  59. {
  60. length = strlen (strIN);
  61.  
  62. for (int i = 0; i < length; i++)
  63. {
  64. strOUT[i] = strIN[length - 1 - i];
  65. }
  66.  
  67. strOUT[length] = '\0';
  68. }
Success #stdin #stdout 0s 5320KB
stdin
random string input
stdout
User Inputted:
random string input

Reverse String is:
tupni gnirts modnar