Guest User

Untitled

a guest
Jun 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <Windows.h>
  5.  
  6. char reversedString[1024] = {0};
  7.  
  8. void printReversedString( char *str )
  9. {
  10.     char *newWord = new char[1024];
  11.     int chAdded = 1;
  12.  
  13.     while ( (*str != NULL) && (*str != ' ') )
  14.     {
  15.         *newWord++ = *str++;
  16.         chAdded++;
  17.     }
  18.  
  19.     *newWord++ = 0;
  20.  
  21.     for ( int i = 0 ; i < chAdded ; i++ )
  22.         *newWord--;
  23.  
  24.     if ( *str != NULL )
  25.     {
  26.         *str++;
  27.         printReversedString( str );
  28.     }
  29.    
  30.     strcat(reversedString, " ");
  31.     strcat(reversedString, newWord);
  32. }
  33.  
  34. void main()
  35. {
  36.     char *pString = new char[1024];
  37.  
  38.     printf("Enter Original String: ");
  39.     gets(pString);
  40.     putchar('\n');
  41.     printReversedString( pString );
  42.     printf("The string reversed is:%s", reversedString);
  43.     Sleep(55*1000);
  44. }
Add Comment
Please, Sign In to add comment