请实现一个函数,把字符串 s 中的每个空格替换成"%20"。
char* replaceSpace(char* s){ int count = 0; for (int i = 0; i < strlen(s); i++) { if (s[i] == ' ') count++; } char* ans = (char*)malloc(sizeof(char) * (strlen(s) + count * 2 + 1)); int i = 0, j = 0; while (i < strlen(s)) { if (s[i] != ' ') { ans[j] = s[i]; i++, j++; } else { ans[j] = '%'; ans[j + 1] = '2'; ans[j + 2] = '0'; i++, j += 3; } } ans[j] = '\0'; return ans; }