Remove extra spaces in the string

int rm_extra_spaces ( char * INPUT) 
{ 
    int len = strlen (INPUT);
     IF (INPUT == NULL || len> MAX_INPUT_LEN) {
         return - . 1 ; 
    } 
    // remove trailing spaces 
    char * INPUT PTR = len + - . 1 ;
     the while (PTR> INPUT && * PTR = == '  ' ) {
         * PTR = ' \ 0 ' ; 
        PTR - ; 
    } 
    // remove header spaces 
    len = 0 ; 
    PTR =INPUT;
     the while (! * PTR = ' \ 0 ' && * PTR == '  ' ) { 
        PTR ++ ; 
        len ++ ; 
    } 
    memmove (INPUT, PTR, strlen (PTR) + . 1 );
     // remove repeated intermediate space 
    char * POS = NULL;
     char * tmp = NULL; 
    PTR = INPUT;
     do { 
        POS = the strchr (PTR, '  ' );
         IF (POS == NULL) {
             BREAK ;
        }
        tmp = pos;
        while (*tmp == ' ') {
            tmp++;
        }
        memmove(pos + 1, tmp, strlen(tmp) + 1);
        ptr = pos + 1;
    } while (1);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/tongyishu/p/11682108.html