繁体   English   中英

C错误“下标值既不是数组也不是指针”

[英]C error “subscripted value is neither array nor pointer”

我在下面的代码段中遇到了一些问题。

#include "stm32f0xx_tim.h"
#include "stm32f0xx_adc.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_conf.h"
#include "adc.h"

void calcSensor(float voltage1, float voltage2, int X, int Y)
{
    float Iload = 0;
    float Vsensor = 0;
    float Rsensor = 0;
    float Vdrop = voltage1 - voltage2;
    uint32_t resistance = 0;
    Iload = Vdrop/Rload;
    Vsensor = Vin - Iload*Rmux - Iload*Rdemux-Vdrop;
    resistance = Vsensor/Iload;
    Rsensor[1][5] = resistance;
    Y++;
    if (Y == 22)
    {
        Y = 0;
        X++;
        if (X == 44)
        {
            X = 0;
        }

    }
}
void initRArray(void)
{
    int x;
    int y;
    for(x = 0; x < 44; x++) 
    { 
        for(y = 0; y < 22; y++)
        {
            Rsensor[x][y] = 0;
        }   
    }
}

错误来了:

Rsensor[1][5] = resistance;

错误与标题相同:

下标值既不是数组也不是指针

我最初将X和Y用作索引,但是切换到0和5以为可能是个问题。 那没有解决。 此外,我还有intRarray函数,该函数将所有值设置为0。此数组可以正常编译,并且使用的是有问题的同一数组。

下面是头文件中数组的声明。

unsigned long int Rsensor[44][22];

您有一个局部变量float Rsensor = 0; 它遮盖了全局数组。 重命名两者之一。

您在程序中具有以下声明

float Rsensor = 0;

这使Rsensor成为float变量,而不是数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM