Guest User

Untitled

a guest
Oct 16th, 2011
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MESSAGE 100
  4.  
  5. int main(void)
  6. {
  7.     char input_message[MESSAGE], termination_char;
  8.     int input, output, message_length;
  9.  
  10.     printf("Enter a sentence: ");
  11.     for (input = 0; input < MESSAGE; input++)
  12.     {
  13.         scanf("%c", &input_message[input]);
  14.         if ( (input_message[input] == '?') || (input_message[input] == '!') ||
  15.              (input_message[input] == '.') )
  16.         {
  17.             termination_char = input_message[input];
  18.         }
  19.     }
  20.  
  21.     printf("Reversal of sentence: ");
  22.    
  23.     message_length = MESSAGE - 1;
  24.  
  25.     for (output = message_length; output >= 0; output--)
  26.     {   // check if end of word
  27.         if ( (input_message[output] == " ") || (output == message_length) )
  28.         {
  29.             for (; (input_message[output] != " ") && (output >= 1); output--)
  30.             {   //output = index of first letter in the word
  31.                 for (; (input_message != " ") && (output < message_length);
  32.                      message_length++)
  33.                 {
  34.                     printf("%c", input_message[output]);
  35.                     // prints the word, char by char
  36.                 }
  37.                 printf(" ");
  38.                 message_length--; // make sure the same space is
  39.                                   // is not done again
  40.             }
  41.         }
  42.     }
  43.  
  44.     printf(" %c\n", termination_char);
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment