我在一函数内定义了一个局部变量,在release版本和debug版本下显示的值不同。
请高手指点!!!

解决方案 »

  1.   

    CString CTelBookDlg::MakeInputTelData(CString strInput)
    {
        
    long int nTelLength,nPos,nNum,nPosTmp;
    char inchar,inchar1;
    char *pOutput,*pOutputTmp;
    CString strOutput;
    BOOL bExistFlag[]={0,0,0,0,0,0,0,0,0,0,0,0}; char s[12];
    s[0]=0x10; s[5]=0x15; s[10]=0x1A;
    s[1]=0x11; s[6]=0x16; s[11]=0x1B;
    s[2]=0x12; s[7]=0x17; 
    s[3]=0x13; s[8]=0x18; 
    s[4]=0x14; s[9]=0x19;  int i; nTelLength=strInput.GetLength ();

    pOutput=(char *)malloc(nTelLength);
    if(pOutput==NULL)
    AfxMessageBox("No Sufficient Memory");
    pOutputTmp=pOutput;
    nNum=0;
    for(nPos=0;nPos<nTelLength;nPos++)
    {
    strcpy(&inchar,strInput.Mid (nPos,1));
    switch(inchar)
    {//
    case '':
    break;
    case 0x00:
    break;
    case 0x08:
    nPos+=10;
    break;
    case 0x10:
    for(i=0;i<12;i++) bExistFlag[i]=0;
    nPos+=4;
    *pOutputTmp=inchar;
    pOutputTmp++;
    nNum++;
    bExistFlag[0]=1;
    break ;
    default :
    if(inchar>=0x11 && inchar<= 0x1B)
    {
    //去除末尾的空格符
    nPosTmp=nPos;
    do
    {
    nPos--;
    pOutputTmp--;
    nNum--;
                  strcpy(&inchar1,strInput.Mid (nPos,1));
    }
    while(inchar1==0x20); pOutputTmp++;
    nNum++;
    nPos=nPosTmp+4;

    //加入格式符号
    i=inchar%0x10;
    bExistFlag[i]=1;
    do
    {
    i--;
    }while(bExistFlag[i]==0);
    i++;
    while(bExistFlag[i]==0)
    {
    bExistFlag[i]=1;
    //*pOutputTmp=s[i];
    //pOutputTmp++;
    nNum++;
    i++;
    }
    }//if
    *pOutputTmp=inchar;
    pOutputTmp++;
    nNum++;
    break;
    }//switch
    }//for
    strOutput=pOutput;
    //CString lengthm;
    //lengthm.Format("%d",nNum);
    //AfxMessageBox(lengthm);
    strOutput=strOutput.Mid (0,nNum);//nNum的值在debug与release下不同。
    free(pOutput);
    return strOutput;
    }
      

  2.   

    应该是又指针或数组变量没有初始化或越界,直接冲掉了nNum的值。你仔细检查一下指针和数组吧!
      

  3.   

    初步看了一下发现strcpy(&inchar,strInput.Mid (nPos,1));这句话有问题。你的inchar只是一个char,而strcpy拷贝的时候会在最后加上一个'\x0'表示字符串结束,这样肯定及时你的strInput.Mid (nPos,1)只是一个字符,也会因为越界而修改了别的变量的值。
    直接用 inchar = strInput[nPos]
      

  4.   

    空指针!
    http://community.csdn.net/Expert/topic/3219/3219449.xml?temp=.6365167
      

  5.   

    问题解决。非常感谢whale!!!发现要学的东西真的好多!
    不过是要将strcpy(&inchar,strInput.Mid (nPos,1));
    换成。inchar = strInput.GetAt(nPos);