问题遇到的现象和发生背景
在进行移位动态数组于另一个函数内部重新申请的时候,会由于地址销毁,造成二次初始化失败,所以改用二级指针进行接收,但是会出现已执行断点指令,请问咋解决
用代码块功能插入代码,请勿粘贴截图
#include <iostream>
using namespace std;
void strmncpy(char* s, int m, int n, char**t);
int main()
{
char s[128] = {'0'};
char* t = new char[102] {0};
int m, n;
cin >> s; // 输入源串
cin >> m >> n; // 输入m和n
strmncpy(s, m, n, &t); // 字符串复制
cout << t << endl; // 输出复制结果
return 0;
}
// 函数strmncpy:字符串的部分复制,将s指向字符串从第m个字符开始的n个字符复制的t中
// 参数:s-指向源字符串,t-指向目标字符串,m-起始位置,n-字符个数
// 返回值:无
void strmncpy(char* s, int m, int n, char**t)
{
// 请在此添加代码,实现函数strmncpy
/********** Begin *********/
s = s + m;
int flag = 0;
if (m > strlen(s))
{
delete[]t;
char**t = new char*;
**t = ' ';
flag = 1;
}
while ((*s != '\0') && (n > 0)&&flag==0)
{
**t = *s;
s++;
t++;
n--;
}
/********** End **********/
}
运行结果及报错内容
我的解答思路和尝试过的方法
用二级指针接受失败了
我想要达到的结果
实现自定义函数,不报错