#include <stdio.h>
#include <string.h>
#include <malloc.h>
char * strtrim(char *sDes, const char *sSrc )
{
char *temp = sDes;
while (*sSrc++ == ' ');
sSrc--;
while ((*sDes++ = *sSrc++) != 0x00);
sDes--;
while (*--sDes == ' ');
*++sDes = 0x00;
return temp;
}
void main()
{
char *sString = " 1 ";
char sTrim[6];
strtrim(sTrim, sString);
printf("*%s*/n", sString);
printf("*%s*/n", sTrim);
}
char* trim( const char* s )
{
static char rel[MAX_LEN];
char* se = 0;
assert( s );
assert( strlen( s ) <= MAX_LEN && strlen( s ) != 0 );
se = s + strlen( s ) - 1;
for( ; isspace( *s ) ; ++s );
for( ; isspace( *se ) ; --se );
strncpy( rel , s , se - s );
return rel;
}