In the C + + language, the words in the word are inverted (the word inverted, the word itself is not inverted), punctuation is not caused. such as a sentence "I come from Tianjin." "and turned upside down to" Tianjin. From Come I ".
c Common library functions are:
Copy Code code 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, the main string is "123456789" and the substring is "234", then return "23456789".
char* strcpy (char* deststr,const char* srcstr) Copy string function
int strcmp (const char* str1,const char* str2) compare two strings
char* strcat (char* deststr,const char* srcstr) connection string
There is no library function that is too appropriate, so find ways to invert it without using a library function. Below is the realization of their own, deficiencies, but also look at the!!!
Copy Code code 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;
The string is first reversed into. nijnait Morf EmOC I
while (J > i)
{
temp = Str[i];
Str[i] = Str[j];
STR[J] = temp;
J--;
i + +;
}
cout << "string =" << str << Endl;
Then to the word part of the reversal, encountered spaces, then determine the end of a word
i = 0;
while (Str[i])
{
if (Str[i]!= ')
{
begin = i;
while (Str[i] && str[i]!= ')
{
end = i;
i++;
}
if (str[i] = = ' Terminator ')//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;
}