/* * Author: Paul A. Parkanzky (firstname.lastname@gmail.com) * * "I am committed to helping Ohio deliver its electoral * votes to the president next year" * -- Walden W. O'Dell (CEO of Diebold, Inc) * * * Works with gcc3.2 on x86 SuSE, gcc3.3 on x86 Gentoo and gcc3.2 on x86 Redhat. * Does not work with gcc2.95 on x86 NetBSD or sparc FreeBSD. * I haven't tried it on any other combinations. * * On Nov 1 the votes are counted correctly. On Nov 2 the total is correct, but * one candidate is "delivered" extra votes at another's expense. */ #include #include #include void printResults(unsigned int *); void paperTrail(char *); char *getDay(); int main() { unsigned int Tally[4] = {0}; unsigned char Other; unsigned char Nader; unsigned char Bush; unsigned char Kerry; char LogMesg[11] = {0}; int Input; char *day; day = getDay(); Bush = 0; Kerry = 1; Nader = 2; Other = 3; while ((Input=getchar())!=EOF) { unsigned char Vote=Input; /* Log to paper receipt */ sprintf (LogMesg,"LOG VOTE: November %s %c\n",day,Vote); paperTrail(LogMesg); /* Add 1 */ if (!isspace(Vote)){ switch (Vote) { case 'B': Tally[Bush]++; break; case 'K': Tally[Kerry]++; break; case 'N': Tally[Nader]++; break; default: Tally[Other]++; break; } } } printResults(Tally); return 0; } /* * This gets a day string for the paper trail log message. * ("first","second","third" or "ith") */ char *getDay() { char *retVal; time_t now_time; struct tm *now; now_time = time(NULL); now = localtime(&now_time); if (now->tm_mday == 1) { retVal = "first"; } else if (now->tm_mday == 2) { retVal = "second"; } else if (now->tm_mday == 3) { retVal = "third"; } else { retVal = (char *)malloc(7); sprintf(retVal,"%ith",now->tm_mday); } return retVal; } /* * Print the results. */ void printResults(unsigned int *Tally) { unsigned char Bush = 0; unsigned char Kerry = 1; unsigned char Nader = 2; unsigned char Other = 3; printf("Kerry: %d\n",Tally[Kerry]); printf("Bush: %d\n",Tally[Bush]); printf("Nader: %d\n",Tally[Nader]); printf("Other: %d\n",Tally[Other]); } /* * This will print a log of the vote to a paper receipt when * the supporting hardware is added. */ void paperTrail(char *mesg) { /* Log to paper trail for extra legitimacy! */ }