Hi all! I coded this function to eliminate spaces before and after a string.
e.g.:
will returnCode:trim(" just a test 123 ");
But I didn't uderstand why the compiler ask for *trim instead of trim.Code:"just a test 123"
Any improvement/suggestion is welcome.
Code:char *trim(char string[100]) { int a, b, c, d; char trimed_string[100]; a = b = c = d = 0; for (a; a < strlen(string); a++) { if (string[a]!=' ' && !b) /* first valid char */ b = a; if (string[a]==' ' && b) { for (d; d < strlen(string)-a;d++) if (string[d+a]!=' ') c = a+d; } } a=0; for (b; b <= c; b++) { trimed_string[a]= string[b]; a++; } trimed_string[ strlen(trimed_string)-10 ] ='\0'; // why -10 ? otherwise it'll return junk return(trimed_string); }



LinkBack URL
About LinkBacks


