2012-05-14 113 views
0

我想将数组传递给函数,但接收到的值只是数组中的第一个值。我究竟做错了什么 ?这是操作中涉及的3个功能。将数组传递到函数错误

void computeCScode (int temp1, int temp2, int code[]) 
{ 
    if((temp1<100)&&(temp2<100)) 
{ 
    code[0]=1; 
    code[1]=0; 
    code[2]=1; 
    code[3]=0; 
} 
else if((temp1<100)&&(temp2>=100&&temp2<=400)) 
{ 
    code[0]=1; 
    code[1]=0; 
    code[2]=0; 
    code[3]=0; 
} 
... 
} 

void invert(int x1, int y1, int x2, int y2, int firstCode[], int secondCode[]) 
    { 
    int ok=1; 
int *temp; 
temp=(int*)malloc(sizeof(firstCode)); 
int aux; 
if(firstCode==0000) ok=1; 
else ok=0; 
... 

}

void cs(HDC hdc, int x1, int y1, int x2, int y2) 
{ 
int firstCode[4]; 
int secondCode[4]; 
FINISHED = FALSE; 
DISPLAY=FALSE; 
REJECTED=FALSE; 
do 
{ 
    computeCScode(x1,y1,firstCode); 
    computeCScode(x2,y2,secondCode); 
    ... 
      invert(x1,y1,x2,y2,firstCode,secondCode); 
    }while(!FINISHED); 
} 

computeCScode,firstCode和secondCode后都OK。但是当它们通过反转时,它们只能使用函数的第一个值。我忘了什么?

+0

请减少您的示例,使其仅包含查看问题所需的代码。你输入的代码太长了。 (通过这样做,你也可以自己找到错误的原因。) – krlmlr

回答

1

invert这部分没有做什么你认为它的作用:

temp=firstCode; 
firstCode=secondCode; 
secondCode=temp; 

如果你真的想交换阵列中的内容,然后使用memcpyfor循环,例如

for (i = 0; i < 4; ++i) 
{ 
    int temp = firstCode[i]; 
    firstCode[i] = secondCode[i]; 
    secondCode[i] = temp; 
} 
+0

我会改变这一点,谢谢。但是,这并不能解决我所遇到的问题 –