#include #include #include typedef unsigned char uchar; typedef unsigned long ulong; /* ordered by political position, from left to right */ enum candidates { NADER = 0, KERRY, OTHER, BUSH, NUM_CANDIDATES }; #define NADER_VOTE 'N' #define KERRY_VOTE 'K' #define BUSH_VOTE 'B' static void count_vote (int arg1, void *arg2) { uchar vote = arg1, *totals = arg2; if (isspace (vote)) return; /* invalid vote */ switch (vote) { case NADER_VOTE: totals[NADER]++; break; case KERRY_VOTE: totals[KERRY]++; break; case BUSH_VOTE: totals[BUSH]++; break; default: totals[OTHER]++; break; } } int main () { int c; ulong totals[NUM_CANDIDATES]; memset (totals, '\0', sizeof (totals)); while ((c = getchar()) != EOF) { count_vote (c, totals); } printf ("Kerry %lu\n", totals[KERRY]); printf ("Bush %lu\n", totals[BUSH]); printf ("Nader %lu\n", totals[NADER]); printf ("Other %lu\n", totals[OTHER]); return (0); }