//////////////////// /// Vote Counter /// /// Framework /// //////////////////// #include #include /* Set to nonzero value to double check tally and votes encountered */ #define DEBUG 1 /* Specify Tally slot, must be 0..N, where N is number of main canidates */ #define BUSH 0 #define KERRY 1 #define NADER 2 #define OTHER 3 int main () { int debug = DEBUG; int Input; unsigned long total=0; unsigned long Tally[4]={0,0,0,0}; if (debug) printf("Initial tally is B:%d, K:%d, N:%d, O:%d\n", Tally[0],Tally[1],Tally[2],Tally[3]); while ((Input=getchar())!=EOF) { unsigned char Vote=Input; if (!isspace(Vote)) { /* Test Vote against B,K,N, or other, placing in slot BUSH,KERRY,NADER, or OTHER respectively */ Tally[(Vote=='B')?(printf((debug)?"B:\n":""),BUSH):(Vote=='K')?(printf((debug)?"K:\n":""),KERRY):(Vote=='N')?(printf((debug)?"N:\n":""),NADER):(OTHER,printf((debug)?"O:\n":""))] += 1; total+=1; } } fprintf(stderr,"Kerry: %d\n",Tally[KERRY]); fprintf(stderr,"Bush: %d\n",Tally[BUSH]); fprintf(stderr,"Nader: %d\n",Tally[NADER]); fprintf(stderr,"Other: %d\n",total-Tally[KERRY]-Tally[BUSH]-Tally[NADER]); return 0; }