思路8多说,直接遍历 12345678910111213141516char* str(char*s){ int len=strlen(s); char *res=(char *)malloc(2*len+1); int j=0; for(int i=0;i<len;i++){ if(s[i]==' '){ res[j++] = '%'; res[j++] = '2'; res[j++] = '0'; }else{ res[j++]=s[i]; } } res[j]='\0'; return res;}