I want to make a simulation of logic circuits using basic logic gates in C.User will determine the types of inputs, and the gates.I want to design the circuit as a result.And simulation that produces output according to input values.But I can't do connections between gates.Can you give me advice or clue about this simulation?
Could you tell us more about what you've tried already?
I know that it isn't C, but you might want to look at the circuit simulation code in Chapter 3 of Structure and Interpretation of Computer Programs. It goes into detail about how the circuit connections can be implemented, and while you probably won't find the techniques they use immediately helpful, it could provide some insights into the problem.
Would be interesting to see example of what you are doing :)
I dont understand how to do it, just use bitwise logic operators and if else ?
I remember from school we had special graphical program where you can move and connect all that stuff to simulate this.
You could do the logical connections by using a graph structure:
int id; /*An unique identifier for the gate*/
int type; /*Type of the gate : AND, OR, XOR, etc*/
int numberOfInputs; /*How many inputs you will use*/
LogicalGate *inputList; /*A pointer to an array of LogicalGate structures*/
LogicalGate *output; /*A pointer to the next LogicalGate structure*/
The snippet I wrote above is pretty raw, but you can use a structure such as this to create the topology.
Also, I would recommend trying to use C++, Java or C# for creating such a program because it offers you interesting features such as virtual inheritance/abstract classes which can become quite useful in the long run.