fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 10
  2. //
  3. /**************************************************************
  4.  * Reverse names
  5.  *
  6.  * ____________________________________________________________
  7.  *This program will reverse the name given.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * User name.
  11.  * OUTPUT
  12.  * Reversed name
  13.  **************************************************************/
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cmath>
  17. using namespace std;
  18. char* reverse(char* string, int size)
  19. {
  20. int length = strlen(string);
  21. char* array = new char [length];
  22. for (int i = 0; i < length; i++)
  23. {
  24. array[i] = string [length-1-i];
  25. }
  26. return array;
  27. }
  28.  
  29. int main()
  30. {
  31. int size = 100;
  32. char* string = new char [size];
  33. char* re;
  34. cout<<"What would you like to enter?"<<endl;
  35. cin.getline(string, size);
  36. re = reverse(string, size);
  37. cout<< re <<endl;
  38. delete [] string;
  39. delete [] re;
  40.  
  41.  
  42. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty