The order of words in an English sentence is reversed, and the order of Characters in the word remains unchanged.
For example, set "Live and learn! "Reversed "! Learn and live"
Consider:
1. Reverse all characters in the entire sentence :"! Nrael DNA edevil"
2. Invert words one by one in a sentence :"! Learn and live "(separated by non-characters and numbers)
# Include "stdafx. H"
# Include <stdlib. h>
# Include <string. h>
# Include <ctype. h>
// Reverse the string start ~ Character Sequence of end
Char * strrev (char * Start, char * end)
{
If (Start> = end)
Return NULL;
Char * ret = start;
Char ch;
While (start <End)
{
Ch = * start;
* Start ++ = * end;
* End -- = CH;
}
Return ret;
}
// Reverse the word order in a sentence
Char * strrevword (char * Str)
{
If (STR = NULL)
Return NULL;
Char * ret = STR;
Int nlen = strlen (STR );
// Reverse the entire string
Strrev (STR, STR + nlen-1 );
Char * Start = STR;
While (* Str)
{
// Separate search characters
While (* STR & (isalpha (* Str) | isdigit (* Str )))
STR ++;
// Reverse the word
If (start <Str)
Strrev (START, str-1 );
// Skip non-characters and numbers
While (* STR &&! Isalpha (* Str )&&! Isdigit (* Str ))
STR ++;
Start = STR;
}
Return ret;
}
Int main (INT argc, _ tchar * argv [])
{
Char STR [] = "Live and learn !!! ";
Strrevword (STR );
Printf ("% s/n", STR );
System ("pause ");
Return 0;
}