Thread: Advice for my system

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    19

    Advice for my system

    Hi guys, thanks for your previous replies to my thread, I now have a system that satisfies my 1st iteration. It does what it is supposed to do, it allows the user to test individual logic gates, through user specified inputs to see what the output will be.

    Looking at the code(Please see the attachment) I know that I will be able to tidy it up and make it more elegant. But what I need advice on now is how do I get the system to allow the user to test multiple gates at the same time.

    To clarify I want my 2nd iteration to be able to allow the user the select the gate they want, specify how many inputs and then specify the values for those inputs. Then allow the user to select another, or ever how many the user would like, setting up in the same way; inputs and the values for the inputs.

    Here lies the problem, I need to specify a run function that can be accessed by the user from the menu, so when they execute it the corresponding switch statement runs the function and the then the output for each of the gates selected will be displayed in the command prompt.

    Now I realise that depending on how many gates the user selects may make it hard to keep track of what gate is producing what output, so I need a way of incrementing an ID number fro each gate. I hope that all make sense, any feedback will be great.

    Thanks again, and thanks for before.

    Archie

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    A lot of code is repeated - for example the input of the "input array", asking how many inputs are wanted. Use functions to avoid repeating code.

    In several places, you do some input, then have a while-loop in case the input was wrong. Using do-while instead of while (or initializing the variable in question to an invalid value) allows you to only write the code to ask the question ONCE.

    Code:
    	if (result == 1){
    		printf("\nOutput = 0\n");
    	}
    	else {
    		printf("\nOutput = 1\n");
    	}
    Could be written in a single line, using printf with %d format.

    I'm sure I could find more, but

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    19
    H,. thanks.

    Even though I am still quite new to C (doing it all again), I can see where I can simplify the code further. For me to incororate a run function so that the user can input multiple gates into the system, how would I go about that? That is what I am stuck on

    Archie

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by qwertysingh View Post
    H,. thanks.

    Even though I am still quite new to C (doing it all again), I can see where I can simplify the code further. For me to incororate a run function so that the user can input multiple gates into the system, how would I go about that? That is what I am stuck on

    Archie
    There are probably several ways to do that, but you most likely will have to build some form of tree data-structure, where each operator has a link to the next operator that it feeds into. You would also have to mark what operation each operand actually is.

    This is not entirely trivial work.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  2. Need advice on video card
    By VirtualAce in forum Tech Board
    Replies: 1
    Last Post: 04-25-2006, 09:33 PM
  3. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM
  5. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 09:21 PM