Main idea: First write the function of the inverse of the word, and then write the whole sentence in reverse order of the function (in which to find the word, found after the call to reverse the inverse of the function, and finally the whole sentence reverse).
Program disadvantage: Only a few common punctuation source code and test procedures can be identified:
Given a string, the string is reversed by word, with punctuation #include <stdio.h> function void Reverse_word in reverse order between//start and end (Char *start, char *e nd) {while (Start < end) {*start = *start ^ *end; *end = *start ^ *end; *start = *start++ ^ *end--; }} char *reverse_sentence (char *str) {char *start = str; char *end = str; while (*end! = ')} {if (*end== ' | | | *end== '! ' | | *end== ', ' | | | *end== '. ' | | *end== '? ') Find a Word {if (Start < end)///Only one letter Word does not reverse reverse_word (start, end-1); while (*end== ' | | | *end== '! ' | | *end== ', ' | | ' *end== '. ' | | *end== '? ') end++; Point to the next word first character start = end; } else end++; } reverse_word (str, end-1);//The entire sentence is reversed in reverse to STR; } int main (int argc, char *argv[]) {char str[] = "Hello, I am glad to see you!"; printf ("%s\n", str); printf ("%s\n", Reverse_sentence (str)); return 0; }
Reverse sentences by word (with punctuation)