64,650
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <malloc.h>
using namespace std;
int main()
{
char *str[2100];//原先很大,我运行时出现错误
int len[10];
char* nowp, *init;
nowp = (char *)malloc(sizeof(char)*100);
init = nowp;
for(int i = 0; i < 2; i++)
{
scanf("%d %s", &len[i], nowp);
str[i] = nowp;
nowp = nowp + len[i] + 1;
}
free(init);
return 0;
}
char* nowp, *init;
nowp = (char *)malloc(sizeof(char));
free(init);//你并没有为init申请内存,所以释放时会出错 你可以free nowp