字符串去空格 c语言实现

void removeSpace(char str[]){ int i=0, is = -1, in = 0; for (;str[i] != '/0';++i){ if (str[i] != ' '){ if (is != -1){ str[is] = str[i]; str[i] = ' '; if (in == 1){ is = i; } else { ++is; } } } else if (is == -1){ is = i; ++in; } else { ++in; } } if (is != -1){ str[is] = '/0'; } } int main(int argc, char* argv[]) { char str[] = " 3 1 2 3 4 56677 3 kk akjfkak kajfka "; removeSpace(str); cout << str; return 0; }

欢迎批评指正哈!多多交流

你可能感兴趣的:(c,语言)