int Switchtest(int swnum) /* Define the function to return an integer (1 or 0) and to take an integer */ { int i = 0; int switches[7]; /* Set all elements of the switches array to a 0 after this */ switches[0] = 0; /* This is long winded, maybe make it a while or for loop */ switches[1] = 0; switches[2] = 0; switches[3] = 0; switches[4] = 0; switches[5] = 0; switches[6] = 0; switches[7] = 0; int powerofbit = 1; /* Set the first power of the bit we want to test (1 as in 0000 0001) */ unsigned int data; /* etc COMEDI vars etc */ data = 128; /* Use this line to test this function without comedi (on windows or at home) */ /* COMEDI READING CODE to put switches into a variable called data HERE!!!!! */ while(i <= 7) /* While or for loop, Simply & the data with powerofbit (resulting in powerofbit if positive)*/ { if((data & powerofbit) == powerofbit) switches[i] = 1; /* Positive results, set that switch number to a 1 (else it remains 0) */ powerofbit = powerofbit + powerofbit; /* Increase bit power to next bit */ /** e.g. -- 0000 0001 then 0000 0010 then 0000 0100 then 0000 1000 etc etc **/ i++; /* increment loop count */ } return switches[swnum]; /* Return to main code with the value of swnum as specified (Switchtest(3) - swnum = 3) */ } /***************** I can now call or test a switch like this: ***************/ int main() { int i; Switchtest(0); Switchtest(1); /** However, this will give no output or use! **/ for(i=0; i<=7; i++) printf("Switch %d, has value of %d\n", i, Switchtest(i)); } /** Ok run this on Windows or Linux or Mac, (code compiles and runs). You should get the following output: Switch 0, has value of 1 Switch 1, has value of 0 Switch 2, has value of 1 Switch 3, has value of 0 Switch 4, has value of 1 Switch 5, has value of 0 Switch 6, has value of 1 Switch 7, has value of 0 Please DON'T copy and paste this into your project! Maybe don't use an if statement to test the bit (its possible). Re-write the function using for loops, maybe structure your array differently. Have the function called differently : i.e. with a string e.g. Switchtest(sw1); Switchtest(sw2); etc etc Hope this helps, but this is an assessed project, copying this code directly could result in yourself failing. The above can be achieved in maybe 1000 different ways. **/