简体   繁体   中英

C error “subscripted value is neither array nor pointer”

I have been having some problems with the segment of code below.

#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;
        }   
    }
}

The error comes the line:

Rsensor[1][5] = resistance;

The error is the same as the title:

subscripted value is neither array nor pointer

I originally had X and Y for indicies but have switched to 0 and 5 thinking it may have been an issue. That did not fix it. Additionally, I have the intRarray function which sets all values to 0. This array compiles fine, and it is using the same array that is having issues.

Below is the declaration of the array in the header file.

unsigned long int Rsensor[44][22];

You have a local variable float Rsensor = 0; which shadows the global array. Rename one of the two.

You have the following declaration in the program

float Rsensor = 0;

This makes Rsensor a float variable, not an array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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