In C ++, words in a sentence are put upside down (between words, words themselves are not put upside down), without punctuation. For example, if "I come from tianjin." is put into an inversion, it becomes "tianjin. from come I ".
C common library functions include:
Copy codeThe Code is as follows: int strstr (const char * string, const char * substring) is used to return all characters after the position of the substring of the Main string. For example, if the main string is "123456789" and the substring is "234", "23456789" is returned ".
Char * strcpy (char * DestStr, const char * SrcStr) Copy string Function
Int strcmp (const char * str1, const char * str2) compares two strings
Char * strcat (char * destStr, const char * srcStr) connection string
There are no library functions that are suitable for the question, so you can find a way to put them upside down without library functions. The following are your own implementations. I hope you can correct them !!!Copy codeThe Code is as follows: # include "stdafx. h"
# Include <iostream>
Using namespace std;
Char * strReverse (char * sourcestr)
{
Int j = 0, I = 0, begin, end;
Char * str = sourcestr;
Char temp;
J = strlen (str)-1;
Cout <"string =" <str <endl;
// First reverse all the strings to. nijnaiT morf emoc I
While (j> I)
{
Temp = str [I];
Str [I] = str [j];
Str [j] = temp;
J --;
I ++;
}
Cout <"string =" <str <endl;
// Perform partial word inversion. When a space is used, the end of a word is determined.
I = 0;
While (str [I])
{
If (str [I]! = '')
{
Begin = I;
While (str [I] & str [I]! = '')
{
End = I;
I ++;
}
If (str [I] = '\ 0') // end character of the string
{
I --;
}
}
While (end> begin)
{
Temp = str [begin];
Str [begin] = str [end];
Str [end] = temp;
End --;
Begin ++;
}
I ++;
}
Cout <"string =" <str <endl;
Return str;
}
Int _ tmain (int argc, _ TCHAR * argv [])
{
Char str [] = "I come from Tianjin .";
StrReverse (str );
Return 0;
}