标题:二维数组拷贝遇到不兼容指针类型传递,求解
只看楼主
szchen2018
Rank: 2
等 级:论坛游民
帖 子:39
专家分:21
注 册:2021-11-20
结帖率:91.67%
已结贴  问题点数:20 回复次数:2 
二维数组拷贝遇到不兼容指针类型传递,求解
程序代码:

typedef struct
{
    uint8_t Key_Adc_Enable;
    const uint8_t *pAdc_Tab;
    uint16_t *pAdc_Val;
    uint8_t adc_TabNumber;    
    uint8_t adc_ValNumber;
} KEY_ADC_CFG_T;

typedef struct 
{
    KEY_ADC_CFG_T *pstKEY_ADC_cfg;
} KeySrv;

typedef struct
{
    KEY_ADC_CFG_T KEY_ADC_CFG_TO[2];
} DISPLAY_CFG_T;

const uint8_t KeyAdcNum_tbl[] =
{
    1,    //ADC1
    2,    //ADC2
};
#define KEY_ADC_NUM (sizeof(KeyAdcNum_tbl) / sizeof(KeyAdcNum_tbl[0]))

uint16_t KeyAdc0Val_tbl[]=
{
    50, 150, 500,
};
#define KEY_ADC0_VAL (sizeof(KeyAdc0Val_tbl) / sizeof(KeyAdc0Val_tbl[0]))

uint16_t KeyAdc1Val_tbl[]=
{
    50, 150, 500,
};
#define KEY_ADC1_VAL (sizeof(KeyAdc1Val_tbl) / sizeof(KeyAdc1Val_tbl[0]))

static const DISPLAY_CFG_T gstDISPLAYConfig =
{
    .KEY_ADC_CFG_TO[0] =
    {
        .Key_Adc_Enable = 1,
        .pAdc_Tab = KeyAdcNum_tbl,
        .pAdc_Val = KeyCusAdc0Val_tbl,
        .adc_TabNumber = KEY_ADC_NUM,
        .adc_ValNumber = KEY_ADC0_VAL,
    },
    .KEY_ADC_CFG_TO[1] =
    {
        .Key_Adc_Enable = 1,
        .pAdc_Tab = KeyCusAdcNum_tbl,
        .pAdc_Val = KeyCusAdc1Val_tbl,
        .adc_TabNumber = KEY_ADC_NUM,
        .adc_ValNumber = KEY_ADC1_VAL,
    },
};

void printf_arrs(int index,int index2,uint16_t arr[index][index2])
{
    int i,j;
    for(i=0;i<index;i++)
    {
        for(j=0;j<index2;j++)
            printf("%d ",arr[i][j]);
        printf("\n");
    }
}

void arrs_copy(int index,int index2,uint16_t arr[index][index2],uint16_t arr2[index][index2])
{
    int i,j;
    for(i=0;i<index;i++)
    {
        for(j=0;j<index2;j++)
        {
            arr[index-1][j]=arr2[i][j];
        }
    }
}

int AdcKeyCode(KEY_ADC_CFG_T *AdcCfg, int *KeySrc)
{
    int i = 0,j=0,res =0,flag = 0,ret = 0;
    (void) res;(void) flag;(void) ret;
    static uint16_t CurKeyVal[4] [4];

    memset(CurKeyVal,0,sizeof(CurKeyVal));

    for (i = 0; i < AdcCfg[i].adc_TabNumber; i++)
    {
        res = ADCScan(NULL, AdcCfg[i].pAdc_Tab[i]); // adc1 adc2

        for (j = 0; j < AdcCfg[i].adc_TabNumber*AdcCfg[i].adc_ValNumber; j++)
        {
            if (j==AdcCfg[i].adc_TabNumber*AdcCfg[i].adc_ValNumber-1)
            {
                //ret = j;
            }
            else
            {
                //ret = j;
            }
            
            if (res <  AdcCfg[i].pAdc_Val[j])
            {
                int KeyTemp =0;
                
                flag = 1;
                ret = j;
                if (i == 0){
                    //是想把AdcCfg[i].pAdc_Val[j]二维数组的第一行拷贝到CurKeyVal第一行,
                    //arrs_copy我在Dev c++验证过是可以的,但这里会报AdcCfg->pAdc_Val不兼容指针类型传递,需要怎么修改才能通过呢
                    arrs_copy(1, 3,CurKeyVal,AdcCfg->pAdc_Val);
                    printf_arrs(3,3,CurKeyVal);
                }
                if  (i == 1){
                }
                    
                KeyTemp = *KeySrc;

                break;
            }
        }
    
    }

    return (ret);
}

int KeyActive(KeySrv *const me, QEvt const *const e)
{
    int iADC_Key = -1;
    .....
    iADC_Key = CustomAdcKeyCode(me->pstKEY_CUS_ADC_cfg,&get_key_src);
    ....
}
搜索更多相关主题的帖子: for int index sizeof ret 
2021-12-27 22:13
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
得分:20 
程序代码:
void arrs_copy(int index,int index2,void *arr,void *arr2)
{
    int i,j;
    for(i=0;i<index;i++)
    {
        for(j=0;j<index2;j++)
        {
            ((uint16_t *)arr)[(index-1)*index2+j]=((uint16_t *)arr2)[i*index2+j];
        }
    }
}
2021-12-28 11:45
szchen2018
Rank: 2
等 级:论坛游民
帖 子:39
专家分:21
注 册:2021-11-20
得分:0 
回复 2楼 diycai
可以,谢谢大佬
2021-12-28 21:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-508016-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025048 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved