- 题目描述:
编写一个函数,将字符串中的每个单词的倒序输出,字符串中以空格分割各个单词,如果碰到数字则跳过。
- 要求实现函数:
void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr);
【输入】
char *pInputStr:指向一个字符串的指针
long lInputLen:该字符串的长度
char *pOutputStr:指向一块输出的内存,和输入的字符串是大小是(lInputLen+1)
【返回】 无
【注意】 只需要完成该函数功能算法,中间不需要有任何IO的输入输出
- 示例
输入:He is a man no12 3456.
返回:eH si a nam on12 3456.
void change(const char *str,int i,int j,char *out)
{
for(int m=i-j;m>0;m--)
{
out[j]=str[i-1];
i--;
j++;
}
out[j]=' ';
}
int _tmain(int argc, _TCHAR* argv[])
{
char str[]="He is a mauytdn no12 4554tytry789";
int len=strlen(str);
char *out=new char [len];
int j=0;
for(int i=0;i<len;i++)
{
if(str[i]==' ')
{
change(str,i,j,out);
j=i+1;
}
if(!(str[j]>='1'&&str[j]<='9'))
change(str,len,j,out);
else
out[i]=str[i];
}
out[len]=' ';
cout<<out<<endl;
return 0;
}
代码不完整 需自己修改