I want to call a function like the following where the first parameter is a member of a structure called as config. In this example the member is called “Filter” which is defined in the structure as an int and returns a char “changeConfig” to signify a change for other code.
changeConfig = changeInt(config.Filter, 0, 9, LCD_PPM);
This format would reduce my code down to a very confined state of affairs as the structure has over 30 members all which need to be managed and changed in a similar fashion individually.
The following function “changeInt” takes in the values and assigns them to the values intMin, intMax and intval which are required by intScroll()
unsigned char changeInt(int pointVal, int iMin, int iMax, char mode){
unsigned char configChange = 0;
dp = 0;
intMin = iMin;
intMax = iMax;
intVal = pointVal;
while(((keyPadBits & MENU) != MENU) && (timeout < TIMEOUT)){
intScroll();
if(keyPadBits & ENTER){
pointVal = intVal; //config.Filter = intVal; //config->Filter?
confirmMin();
}
}
return changeConfig;
}
This all compiles well and good and allows me to change the value in the function intScroll() but it will only save the value back to the structure config if “pointVal” is replaced with
“config.Filter” or another member. The problem is I want to be able to define the member in the function call.
Any suggestions?
Do I need to start bringing pointers in to solve the issue?
Pass a pointer to the
intthat you wish to modify:When you need to modify the value, you need to de-reference the pointer:
When you call the function, pass the address of the variable that you wish to modify: