1. 程式人生 > >C: 字符數組中的空去掉

C: 字符數組中的空去掉

\n main urn change HA chang != hang ear

#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: 字符數組中的空去掉