Ok, well you are trying...try this.
Code:
char *Trim(char *source)
{
int len = strlen(source);
if(len == 0){char *error = malloc(1); return error = 0;}
char *target = malloc(len);
int a = 0;
while(a < len)
if(!isspace(source[a++]))
break;
int x = len;
while(x > 0)
if(!isspace(source[x--]))
break;
int i = 0;
for(i = a; i <= x; i++)
*target++= source[i];
target[strlen(target)-1] = 0;
return target;
}
But remember that because the memory for the target string is allocated within the function, (has to be), do not allocate for it in the main program:
char string[] = " Programming is fun !!! ";
char *trim = malloc(strlen(string));
trim = Trim(string);
// !...Memory Leak...! //
char *trim = Trim(string);
// !...Correct...! //