#include
#include
#define MAX_LEN 128
/**
* 该函数的作用为当有两个连续空格出现时,
* 去掉多余的那个空格。因为是循环执行,故当有多个
* 连续空格出现时,也可以删到只剩一个空格。
*/
int fun( char *input_str, char *output_str )
{
int i, j;
char *p;
strcpy( output_str, input_str );
p = output_str;
for( i = 0; i < strlen( p ); i++ )
{
if( *( p + i ) == ' ' )
{
if( *( p + i + 1 ) == ' ' )
{
j = i + 1;
while( *( p + j + 1 ) != '\0' )
{
*( p + j ) = *( p + j + 1 );
j++;
}
*( p + j ) = '\0';
}
else continue;
}
else continue;
}
return 0;
}
/* this is a test */
void main()
{
char input[]="this is a input str for test!";
char output[ MAX_LEN ];
fun( input, output );
printf("befor run fun, str is:[%s]\n", input );
printf("after run fun, str is:[%s]\n", output );
}