点击(此处)折叠或打开
-
#include "stdafx.h"
-
#include "string.h"
-
#include "stdlib.h"
-
-
#define MAX_STR_LEN 256
-
/*ZG:将输入的英文语句,反向输出
-
*eg:
-
*Input :"I am a student"
-
*Output:"student a am I"
-
*/
-
int revert_en_sentence(char *pIn,char *pOut)
-
{
-
int i = 0, len = 0;
-
if(NULL==pIn || NULL==pOut)
-
{
-
return -1;
-
}
-
char *pI = pIn;
-
char *pO = pOut;
-
char *pT = pIn;
-
-
printf("%s\n",pI);
-
/*先将pT移至最后一字符*/
-
while('\0'!=*pT)
-
{
-
pT++;
-
}
-
pT--;//回退一个char,指向倒数第一个非'\0'字符
-
-
while(pT!=pI)
-
{
-
if(' '!=*pT)
-
{
-
pT--; //有循环找出口
-
len++;
-
continue;
-
}
-
else
-
{
-
for(i=0;i<len;i++)
-
{
-
*pO = pT[i+1];
-
pO++;
-
}
-
*pO = ' ';
-
pO++;
-
len = 0;
-
pT--;
-
}
-
-
}
-
-
for(i=0;i<=len;i++)
-
{
-
*pO = pT[i];
-
pO++;
-
}
-
-
pO++;
-
*pO = '\0';
-
-
pOut = pO;
-
-
}
-
-
int _tmain(int argc, _TCHAR* argv[])
-
{
-
char array [MAX_STR_LEN] = "I am a student";
-
//char array [MAX_STR_LEN] = "student";
-
char strout[MAX_STR_LEN] = "";
-
-
revert_en_sentence(array,strout);
-
-
printf("%s\n",strout);
-
-
system("pause");
-
return 0;
- }