Home > Software engineering >  How can I change the value of a variable in a struct?
How can I change the value of a variable in a struct?

Time:09-17

I'm currently doing my dissertation and a problem appeared that I cannot solve.

I need to change a single variable in a struct, but I can't find the definition of this variable, the code is not mine and it's massive so I don't know what to look for. The struct is defined like this:

typedef struct
{
    double maxAperture; 
    double minAperture; 
    double A1; 
    double D3; 
} electric_gripper;

I need to change the value of the minAperture but I can't find how. There are a lot of constructors that initialize this struct and the function that is supposed to define the values if like this:

void Planner::setElectricGripper(ElectricGripper &egripper)
{
    this->egripper = egripper;
}

I've tried searching everywhere in the code for "egripper" but I can't find any values. I wish I could show more code but like I said it's not created by me and it's massive so I can't show anything. Please help. Thank you

CodePudding user response:

The structure should be defined like this:

 typedef struct electric_gripper
    {
        double maxAperture; 
        double minAperture; 
        double A1; 
        double D3; 
    } electric_gripper;

If you want to change maxAperture you can do as follows:

electric_gripper test;
test.maxAperture = 100;

CodePudding user response:

typedef struct
{
    double maxAperture;
    double minAperture;
    double A1;
    double D3;
} electric_gripper;

electric_gripper egripper;
void setElectricGripper(electric_gripper &egripper1)
{
    egripper1.maxAperture = 11.0;
    this.egripper = egripper1;
}
  • Related