Here is how I would implement the code (from which you should be able to figure out how to implement your code with pointers)
Code:
void toggle_single_solenoid(unsigned char button, unsigned char *prev_button, unsigned char *relay_fwd)
{
if (button && !prev_button) //don't keep toggling if they hold the button
*relay_fwd = !(*relay_fwd);
*prev_button = button;
}
call it like this:
Code:
toggle_single_solenoid(p1_sw_trig, &prev_p1_sw_trig, &relay1_fwd);
Remember to declare prev_p1_sw_trig and change the variables to whichever switches and relays you want.