#include<iostream>
using namespace std;
char * MyReversal(char *src);
int main(void){
char *src = "chinese people";
cout<<"The reversal string is:"<<MyReversal(src)<<endl;
return 0;
}
char *MyReversal(char *a){
char *ptt = (char *)malloc(strlen(a));
ptt = a;
static char *ftt = (char *)malloc(strlen(a));
*ftt = '\0';
char step[] = " ";
/**
* char *strdup(const char *s)
* strdup()会先用malloc()配置与参数s
* 字符串相同的空间大小,然后将参数s字
* 符串的内容复制到该内存地址,然后把
* 该地址返回,该地址最后可以利用free()
* 来释放。
**/
/**
* char *strtok(char*s,char*delim);
* 分解字符串为一组字符串,s为要分解的
* 字符串,delim为分隔符字符串.
* 说明:首次调用时,s指向要分解的字符串
* 之后再次调用要把s设成NULL.
**/
char *token = strtok( strdup(a),step);
while(token != NULL)
{
/**
* char *strrev(char *s);
* 功能:把字符串s的所有字符的顺序颠倒过来.
**/
strcat(ftt,strrev(token));
strcat(ftt," ");
token = strtok( NULL,step);
}
*(ftt + strlen(a)) = '\0';
return ftt;
}