写一个函数,将字符串中空格替换为%20。样例:"abc defgx yz"替换为"abc%20defgx%20yz"。 这道题是一道简单的字符和字符串替换题,字符的替换直接用指针即可,每次都需要把空格后的字符串保存到一个数组中,然后把空格替换为%20后再将刚刚拷贝的字符串拷贝到%20的后面,代码如下:


Fun(char *str) { char *p = str; char arr[20]; while (*p != '\0') { if (*p == ' ') { strcpy(arr, p + 1); *p = '%'; *(p + 1) = '2'; *(p + 2) = '0'; strcpy(p + 3, arr); p = p + 3; continue; } p++; } }