Help for my output array

This is a discussion on Help for my output array within the C Programming forums, part of the General Programming Boards category; Hi Guys, I having trouble with my output array. The system works fine, in that it takes input from the ...

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

    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:
    ...int 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);
    		scanf("%d",&array[i]);
    		while(array[i]!=0 && array[i]!=1){
    			printf("Value must be 0 or 1. Please try again:\n");
    			scanf("%d",&array[i]);
    		}
    	}
    
    	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
    	}*/
    Thanks

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    How 'bout another "for" loop nesting from here:
    Code:
    		}
    	}
    
    	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, 05: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, 11:09 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21