Reverse sentences by word (with punctuation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.