I am trying to test a logic function from four inputs a,b,c and d.
Each input is either 0 or 1.
I have been trying to accomplish this with arrays.
I want to pass back a 1 if a column in logicXY array matches that of the combLogic array.
int comb(int** combLogic, int** logicXY){
int x, y, logicOut;
for ( x = 0; x < 4; x++ ){
if (logicXY[0][x] == combLogic[x]){
logicOut = 1;
}
}
return logicOut;
}
int main void(){
int** combLogic[4] = {a,b,c,d}; /*logic input*/
int** logic[4][4] = {{1,0,0,1}, {1,0,1,1}, {0,1,0,0}, {0,1}}; /*return 1 if any of these combinations match the logic input*/
int comb(combLogic, logicXY); /*send to function*/
}
I know the function is not complete but I don't think I am passing the arrays correctly. I have read a number of tutorials but I cant seem to grasp the theory.
EDIT I have got a few steps forward but it still isn't working. This is what I have now.
Function declaration in .h
int comb(logicInput,logicTest);
Function in .c
/* Function - Combination */
int comb(int** logicInput, int** logicTest){
int x, y, logicOut;
for ( x = 0; x < 4; x++ ){
if (logicTest[0][x] == logicInput[x]){
logicOut = 1;
}
}
return logicOut;
}
The loop in part of the main.c
int output = 0;
int logicInput[4] = {0,1,1,1};
int logicTest[4][4] = {{1,0,0,1}, {1,0,1,1}, {0,1,0,0}, {0,1,1,1}};
int comb(logicInput,logicTest);
output = comb;
The code steps over the int comb(logicInput,LogicTest)
and never carries out the function.
If I take out int
from the line then it carries out the function, returns the value but when the value is written to output it is nothing like the value that was returned from the function.
EDIT
I have made a few changes to the code so it does appear to work and with only one warning from the compiler for the function declaration in .h that I cannot seem to fix.
warning: parameter names (without types) in function declaration [enabled by default]
Function declaration in .h
int comb(logicInput,logicTest);
Function in .c
int comb(int** logicInput, int** logicTest){ /*Points to the arrarys in the main program*/
int x, i, logicOut;
for(i = 0; i < 4; i++){ /*test each column*/
for ( x = 0; x < 4; x++ ){ /*test each row*/
if (logicTest[i][x] == logicInput[i][x]){
logicOut = 1;
break;
}
}
if(logicOut == 1)break; /*Break when logicOut == 1 the first time it happens*/
}
return logicOut;
}
Loop in main.c
int output;
int logicInputC1[4] = {0,1,0,1};
int logicTestC1[4][4] = {{1,0,0,1}, {1,0,1,1}, {0,1,0,0}, {0,1,0,1}};
output = comb(logicInputC1,logicTestC1);
If I deviate from this code I just seem to end up with the compiler failing to build and even more warnings.