#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr)
/*【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO 的输入输出
示例
输入:"abc def gh i d"
输出:"abc,def,gh,i,d," */
#include <stdlib.h>
#include <string.h>
void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr)
/*【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO 的输入输出
示例
输入:"abc def gh i d"
输出:"abc,def,gh,i,d," */
#include<stdio.h>
#include<stdlib.h>
void DivideString(char *pInputStr,char *pOutputStr)
{
char * temp = pOutputStr;
while( *pInputStr == ' ')
pInputStr++;
//char * k = pInputStr;
//printf("%s\n",k);
//while(*k++) //k与pInputStr不同步
while(*pInputStr)
{
if( *pInputStr != ' ')
{
*temp++ = *pInputStr++;
}
else
{
while( *pInputStr == ' ' )
{
*temp = ',';
pInputStr++;
}
temp++;
}
//printf("%s\n",temp);
}
*temp = '\0';
//*temp ;
// if( *(temp-1) == ',')
// *(temp-1) = ' ';
//pOutputStr = temp;
}
int main()
{
int len = 0;
char * pInputStr = " I'm a bloody man. ";
char * c = pInputStr;
while(*c++)
{
len++;
}
char *pOutputStr = (char *) malloc(sizeof(char)*len);
//pOutputStr = pInputStr;
DivideString(pInputStr, pOutputStr);
printf("%s\n",pInputStr);
printf("%s\n",pOutputStr);
delete[] pOutputStr;
system("pause");
return 0;
}