编译运行后,老是跳出一个提示框,提示“0x24581400”指令引用的“0xcccccccc”内存。该内存不能为“written”.
请高手求解#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;char* tiqu(char *dest, char *source)
{
char *str=dest;
 
while(*source)
{
if(*source=='#')
{
source++;
}
else
{
*dest++=*source++;
}
}
*dest='\0';
return str;}
int main(int argc, char* argv[])
{
char *oldW="#abc#d#e#f";
char *newW; tiqu(newW,oldW);    cout<<newW; return 0;
}

解决方案 »

  1.   

    char *newW;
    给分配下内存空间应该就没问题了
      

  2.   


    我给它赋了个值后,还是出问题。如,我赋值:char *newW=“a”;
      

  3.   

    char oldW[100]="#abc#d#e#f";
    char newW[100];
      

  4.   

    char *dest = new char[10];
    memset(dest,0,10);
    没有初始化
      

  5.   

    int main(int argc, char* argv[])
    {
    char *oldW="#abc#d#e#f";
    char *newW=new char[1000]; tiqu(newW,oldW);    cout<<newW; return 0;
    }
      

  6.   

    分配内存的意思是:
    new ...
    malloc ...