C语言删除字符数组中的空格

一个删除字符数组中空格的功能,见代码

#include <stdio.h>
#include <string.h>
#include <memory.h>
void clearStringAllspace(char *s)
{
    
    
    char *temp = s;
    while (*temp) {
    
    
        if(*temp != ' ' && *temp != '\t'){
    
    //这里一定不能是||
            *s++ = *temp;
        }
        temp++;
    }
    *s = '\0';
}
int main(int argc, char *argv[])
{
    
    
    char buf[] = "      abc   edf    ";
    clearStringAllspace(buf);
    printf("buf=%s=====\n", buf);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/cp_srd/article/details/104279201