删除char*变量前后的空格

 

删除char*变量前后的空格

 

/*Delete the blank that is in char* varible*  
 * TODO Robin*/

#include <stdio.h> #include <string.h> #include <stdlib.h> char* eat_sp_mcw(char *src){     /* char * ori = strdup(src);        char * des =  malloc(128);        printf("ori = %s\n", ori);        printf("src = %s\n", src);        printf("des 0 = %s\n", des);        while(*ori){        if(*ori != ' '){      *des = *ori;      des++;      }      ori++;      }      printf("des 1 = %s\n", des);      *des = '\0';      printf("des 2 = %s\n", des);      return des;*/         char * s = strdup(src);         char *e;

        while (*s == ' ') ++s;         if (*s)             for (e = s + strlen(s); *--e == ' '; *e = '\0');         return s; }

int main(int argc, char** argv, char** envp){     char * c1 = "  china  ";     printf("%s\n", eat_sp_mcw(c1));     return 0; }


 

 

你可能感兴趣的:(删除char*变量前后的空格)