<p3****@gmail.com> wrote:
typedef unsigned short WORD;
struct cube {
WORD t;
WORD f;
};
typedef struct cube CUBE;
CUBE cubes[MAX_VARS+1][MAX_CUBES];
And i have to make a procedure that will read from the keyboard
binaries and activate the .t or .f of cubes array accordingly.
Will activate 1 in .t if if we have 1 in that place, 1 in .f if we have
0 in that place and 0 in both places if that place has a '-'.
EXAMPLE:
IF I INSERT P= 1010001 WILL MAKE:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0101110)
If i put P = 101-001 will make:
cubes[0][j].t = (1010001)
cubes[0][j].f = (0100110)
You have embedded a fairly simple problem in a lot of non-issues. Including
a two-dimensional array that has nothing to do with your apparent problem.
I think the word you want for "activate" is "set". In C, the word for
procedure is function. You can not read binary from a keyboard, what you
can do is read characters and convert the characters into binary. Defer the
'-' problem at first, if there is a hyphen in the input, replace it with a
"don't care", either 1 or 0. Having done that (and ignoring the seven bit
situation), if k contains the binary input, then,
char a, b;
a = k does the .t thing
b = ~k. does the .f thing. (~ is one's complement)
Then handle the hyphen. You can force a 0 by selective use of the &
operator, note that 1 & 0 = 0 and 0 & 0 is also 0. So the right bit is
often called a "mask".
The word cube seems like an improbable name for a thing with only two
constituent elements.
I suggest you get these basics working and then and only then incorporating
what you have into an array.