#include <iostream> #include <string> using namespace std; void ReverseStr(char* str_in,char* str_out); void Reverse(char *pBegin,char *pEnd); int main() { char* str_resever="I am a student"; char* str_return=""; ReverseStr(str_resever,str_return); system("pause"); return 0; } void ReverseStr(char* str_in,char* str_out) { if (str_in==NULL) { return; } char *pBegin=str_in; char *pEnd=str_in; while (*pEnd!='\0') { pEnd++; } Reverse(pBegin,pEnd); pBegin=str_in; pEnd=str_in; while (*pEnd!='\0') { if (*pBegin==' ') { pBegin++; pEnd++; continue; } else if (*pEnd==' ' || pEnd=='\0') { Reverse(pBegin,pEnd--); pBegin=pEnd; } else { pEnd++; } } } void Reverse(char *pBegin,char *pEnd) { if (pEnd==NULL || pBegin==NULL) { return; } char temp; while (pBegin<pEnd) { temp=*pBegin; *pBegin=*pEnd; *pEnd=*pBegin; pBegin++; pEnd--; } } </string></iostream>