C: 字符数组中的空去掉

Posted timer_go

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C: 字符数组中的空去掉相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include <string.h>

int main()
{
    char a[50] = "nearby!                 ";
    int i, j;
    int count = 0;
    for (i = 0, j = 0; a[i]; i++)
    {
        if (a[i] != ‘ ‘){
            a[j++] = a[i];
        }
    }
    a[j] = ‘\0‘;

    printf("the changed string is: %s,%s\n",a, a);
    return 0;
}

以上是关于C: 字符数组中的空去掉的主要内容,如果未能解决你的问题,请参考以下文章