Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MESSAGE 100
- int main(void)
- {
- char input_message[MESSAGE], termination_char;
- int input, output, message_length;
- printf("Enter a sentence: ");
- for (input = 0; input < MESSAGE; input++)
- {
- scanf("%c", &input_message[input]);
- if ( (input_message[input] == '?') || (input_message[input] == '!') ||
- (input_message[input] == '.') )
- {
- termination_char = input_message[input];
- }
- }
- printf("Reversal of sentence: ");
- message_length = MESSAGE - 1;
- for (output = message_length; output >= 0; output--)
- { // check if end of word
- if ( (input_message[output] == " ") || (output == message_length) )
- {
- for (; (input_message[output] != " ") && (output >= 1); output--)
- { //output = index of first letter in the word
- for (; (input_message != " ") && (output < message_length);
- message_length++)
- {
- printf("%c", input_message[output]);
- // prints the word, char by char
- }
- printf(" ");
- message_length--; // make sure the same space is
- // is not done again
- }
- }
- }
- printf(" %c\n", termination_char);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment