/******************************************************************* Copyright(c) 2016, Harry He All rights reserved. Distributed under the BSD license. (See accompanying file LICENSE.txt at https://github.com/zhedahht/CodingInterviewChinese2/blob/master/LICENSE.txt) *******************************************************************/ //================================================================== // 《剑指Offer——名企面试官精讲典型编程题》代码 // 作者:何海涛 //================================================================== // 面试题5:替换空格 // 题目:请实现一个函数,把字符串中的每个空格替换成"%20"。例如输入“We are happy.”, // 则输出“We%20are%20happy.”。 #include <cstdio> #include <cstring> #if 0 /*length 为字符数组str的总容量,大于或等于字符串str的实际长度*/ void ReplaceBlank(char str[], int length) { if (str == nullptr && length <= 0) return; /*originalLength 为字符串str的实际长度*/ int originalLength = 0; int numberOfBlank = 0; int i = 0; while (str[i] != '