Thread: Polling an Array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    Delaware
    Posts
    47

    Polling an Array

    I want to find the value occurs most in an 8 integer array. Here is the code that I have. It does compile, but has not been tested.

    Code:
    int POLL (int *RANGE_ARRAY) {
    	
    		int d = 0;
    		int e = 0;
    		int f = 0;
    		int g = 0;
    		int h = 0;
    		int j = 0;
    		int	k;
    		int m = 0;
    		int n = 0;
    		int p;
    		
    		for (k = 0; k < 8; k++) {
    			if (RANGE_ARRAY[0] == RANGE_ARRAY[k]) d++;
    			if (RANGE_ARRAY[1] == RANGE_ARRAY[k]) e++;
    			if (RANGE_ARRAY[2] == RANGE_ARRAY[k]) f++;
    			if (RANGE_ARRAY[3] == RANGE_ARRAY[k]) g++;
    			if (RANGE_ARRAY[4] == RANGE_ARRAY[k]) h++;
    			if (RANGE_ARRAY[5] == RANGE_ARRAY[k]) j++;
    			if (RANGE_ARRAY[6] == RANGE_ARRAY[k]) m++;
    			if (RANGE_ARRAY[7] == RANGE_ARRAY[k]) n++;
    	}
    			if (d >= (e & f & g & h & j & m & n)) p = 0;
    			if (e >= (d & f & g & h & j & m & n)) p = 1;
    			if (f >= (e & d & g & h & j & m & n)) p = 2;
    			if (g >= (e & f & d & h & j & m & n)) p = 3;
    			if (h >= (e & f & g & d & j & m & n)) p = 4;
    			if (j >= (e & f & g & h & d & m & n)) p = 5;
    			if (m >= (e & f & g & h & j & d & n)) p = 6;
    			if (n >= (e & f & g & h & j & m & d)) p = 7;
    			
    		return (p);	
    	}
    Does this look right or is there a better way of doing this?
    Last edited by danlee58; 01-30-2015 at 03:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polling vs. Interrupts
    By NewGuy100 in forum C Programming
    Replies: 4
    Last Post: 09-30-2005, 12:43 AM
  2. keyboard polling
    By krappa in forum Game Programming
    Replies: 16
    Last Post: 06-15-2004, 04:44 PM
  3. Polling the Public....How long have you used CP.com?
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 44
    Last Post: 01-13-2003, 07:05 AM
  4. Keyboard polling loop
    By Paul Balme in forum C Programming
    Replies: 5
    Last Post: 10-22-2001, 05:30 PM