From d49628ba3a1d331acdce3a48a90f800374cc93bc Mon Sep 17 00:00:00 2001 From: xw_y_am Date: Wed, 26 Jun 2019 19:07:55 +0800 Subject: [PATCH] str_word_reversed --- str_word_reversed.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 str_word_reversed.c diff --git a/str_word_reversed.c b/str_word_reversed.c new file mode 100644 index 0000000..2fc97a2 --- /dev/null +++ b/str_word_reversed.c @@ -0,0 +1,27 @@ +#include + +void show_word_reversed(char *str) +{ + char sign, *end, *seek = str; + while (*seek != '.' && *seek != '?' && *seek != '!') seek += 1; + end = seek; + sign = *end; + *seek-- = 0; + for (; seek > str; seek--) + if (*seek == ' ') { + *seek = 0; + printf("%s ", seek + 1); + } + printf("%s%c\n", str, sign); + for (; seek < end; seek++) + if (*seek == 0) + *seek = ' '; + *end = sign; +} + +int main() +{ + char buf[] = "Let's test this program!"; + show_word_reversed(buf); + return; +}