我的代码如下 sy2 是 个 CDialog类,  hanshu 是个CDocument 类
class sy2 : public CDialog//对话框类
{
// Construction
public:
int a[100],b[100],count1,flag1;
int f2_scanf(int a[],int b[]);
}
class hanshu : public CDocument//函数类 各种数学函数
{
 
public:

double xishu[100];
int flag,count;
int f_scanf(double xishu[]);//读取系数
}我现在想把 count =count1, 把a[] b[]存入xishu[] 数组中
我的count a[]  b[]  是在 sy2下给一个编辑框输入的数据的记录(因为要UpdateData(TRUE)不能直接在hanshu中读取)  我的count a[]  b[]  在传过去之前我都测试过,没错,但是每次传递过去总是出错,高手帮忙看下错在哪里
    
    
  

解决方案 »

  1.   

    读取编辑框的函数:
    int sy2::f2_scanf(int a[],int b[])
    {

    UpdateData(TRUE);
    int c[100]={0},i;
    count1=0;
    flag1=1;
    for(i=0;i<m_cs.GetLength();i++)
    {
    if(!(m_cs.GetAt(i)=='x'||m_cs.GetAt(i)=='^'||(m_cs.GetAt(i)>='0'&&m_cs.GetAt(i)<='9')||m_cs.GetAt(i)=='+'||m_cs.GetAt(i)=='-'))
    {
    MessageBox("你的输入不合法,请检查后重新输入~~");
    flag1=0;
    }
    if(m_cs.GetAt(i)=='-') c[count1]=-1;
    if(m_cs.GetAt(i)=='x')
    {
    a[count1]=m_cs.GetAt(i-1)-'0';
        b[count1]=m_cs.GetAt(i+2)-'0';
       if(c[count1]==-1) a[count1]=-a[count1];
       count1++;
    }
    } return flag1;
    }传递的函数  int hanshu::f_scanf(double xishu[])
    {
    sy2 dlg;
    int i;
    flag=dlg.flag1;
    count=dlg.count1;
    for(i=0;i<count;i++)
    {
    xishu[2*i]=dlg.a[i];
    xishu[2*i+1]=dlg.b[i];
    } return flag;
    }
    我刚刚接触MFC 好多都不会 请指教
      

  2.   

    这里有几个问题:
    1、xishu数组的长度应该是数组a和b的和,要不你合并的时候会越界2、你的函数可以改成int f2_scanf(int* a, int nLen1, int* b, int nLen2); 
       这样赋值的时候判断一下长度,避免越界。特别是数组作为参数的时候3、我的count a[]  b[]  在传过去之前我都测试过,没错,但是每次传递过去总是出错
    你看看你传递的函数int hanshu::f_scanf(double xishu[]) 

    sy2 dlg;   // 这是一个临时变量,你在这里用的时候有调用了f2_scanf这个函数了吗?
                          // 也是说你这里用的时候sy2中的数据有初始化了吗?
                          // 调试看一下下面dlg相关的参数数据是不是正确的?
    int i; 
    flag=dlg.flag1;    
    count=dlg.count1; 
    for(i=0;i <count;i++) 

    xishu[2*i]=dlg.a[i]; 
    xishu[2*i+1]=dlg.b[i]; 


    return flag;