问答题

使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,补充空出的代码。函数convert(char*des,char*str,char c,char*str2)的功能是:如果str中包含字符“!”,则替换成’a’;如果str中包含字符“&”,则替换成’b’;如果str中包含字符“*”,则替换成str2。并用函数返回目标转换后的指针。注意:只能补充函数convert(char*des*char*str,char*str2).#include<iostream.h>#include<cstring>#defineMAXLEN1024void convert(char*des,char*Str,char*str2){}void main(){char dest[MAXLEN];char* str="!&cefghi*!&";char*str2="jklm";convert(dest,str,str2);cout<<dest<<endl;return;}

【参考答案】

正确答案:des[0]=0; char temp[2]={0,0}; for(int i=0;str[i]!=NULL;......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)