icoding的数据结构并没有一个测试代码,其都是直接编写一个函数的形式,因此很难知道自己的实际输出是什么。针对部分题目,我编写了一系列测试代码以供大家进行数据输出的测试。
请先将你的代码复制到int str_replace(const char *in, char *out, int outlen, const char *oldstr, const char *newstr)函数中然后修改main函数完成测试样例的输入
在代码开头有个修改提示,请按照提示操作修改即可。
#include#include //#include "dsstring.h" int str_replace(const char *in, char *out, int outlen, const char *oldstr, const char *newstr){ //TODO } int main(){ char in[]="abcc";//可修改 char out[100]; char oldstr[]="a";//可修改 char newstr[]="22";//可修改 int rep=0; int oulen=20;//可修改 //以下请勿修改// printf(">>icoding 串匹配n n"); printf("===开始测试===n"); printf("————原始串————n %sn",in); printf("n>>目标将字符串 %s 替换为 %s n>>out的长度为 %dn>>正在替换n",oldstr,newstr,oulen); rep=str_replace(in,out,oulen,oldstr,newstr); printf("<<替换成功!替换次数==%dn————替换串————n %snn",rep,out); printf("n如遇替换串输出为空,请检查:n①是否在return前完成对out的赋值操作n②是否在字符串最末尾处加上'\0'n"); }



