多个空格合并成一个空格

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

void f(char *c){

    char *p=c;

    while(*c){

        while(*c==' '&& *(c+1)==' '){

            c++;

         }

        *p=*c;

        p++;c++;

    }

    *p='\0';

}

void func(char* pS, char c)
{
    char *p=pS;//两个标志位
    char *q=pS;
 
    int num=0;
    if(pS==NULL)
        return;
    while(*p!='\0')
    {
        if(*p!=c)
        {
            *q++ = *p;
            num=0;
        }else if(*p==c &&num==0){
            *q++ = *p;
            num++;
        }else{
            num++;
        }
        p++;
    }
    *q='\0';
}

猜你喜欢

转载自blog.csdn.net/jack_rose_l/article/details/82115390
今日推荐