Thread: Help for my output array

  1. #1
    Registered User
    Join Date
    Feb 2009

    Help for my output array

    Hi Guys, I having trouble with my output array. The system works fine, in that it takes input from the user and runs the correct logic and then ouputs it.

    I have decided to include an output array, so; 1) The user selects the logic gate they want to test.
    2) The user then selects how many inputs they would like.
    *3) I have just decided to add this in, the user then selects how many outputs they would like.
    4) The user then sets the values for the inputs.

    What I am having a problem with now is that I would like the system to printf() the output as many times specified by the user.

    eg, An AND gate has been selected, and 2 inputs have been declared and 3 outputs have been declared, the input values have been assigned to the input array. Once the gate has applied the bitwise operator, it outputs the response to the command prompt. I want it to display as so; Output = [1,1,1]. Instead of just Output = 1 or 0, I want it to output as many times as the user specified for the output array.

    Here is what I have;
    Code: and(int n, int o)
    	printf("\nPlease Set The Values For Your Inputs: ");
    	int array[n]; ..input array
    	int output[o]; //the output array
    	int i = 0;
    	for (i = 0; i < n; i++){
    		printf("Enter input %d:", i);
    		while(array[i]!=0 && array[i]!=1){
    			printf("Value must be 0 or 1. Please try again:\n");
    	int result = array[0];
    	for(i = 1; i < n; i++)
    	   result &= array[i];
    	printf("\nOuptut = %d\n", result);
    	/*int j = 0;
    	for (j=0; j < o; j++){
    		printf("%d", output[j]); //Just to see if it worked, but nope

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    How 'bout another "for" loop nesting from here:
    	int result = array[0];
    	for(i = 1; i < n; i++)
    Of course maybe then you want to move the declaration up.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Output an array in a textbox
    By Diablo02 in forum C# Programming
    Replies: 5
    Last Post: 10-18-2007, 03:56 AM
  2. Array output strange
    By swgh in forum C++ Programming
    Replies: 1
    Last Post: 12-09-2006, 06:58 AM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM