Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void Initialize();
- void Processvotes();
- void printResults();
- typedef struct info {
- char name[20];
- int votes;
- }info;
- info electionCandidates[6];
- int spoiltVotes=0;
- FILE *electionInfo;
- int main()
- {
- Initialize();
- Processvotes();
- //printResults();
- return 0;
- }
- void Initialize() {
- int i;
- for(i=0;i<7;i++){
- electionCandidates[i].votes=0;
- }
- }
- void Processvotes() {
- int i;
- int voteHolder[365];
- electionInfo = fopen("elections.txt","r");
- fseek(electionInfo, 0L, SEEK_SET);
- for (i=0;i<7;i++){
- fgets(electionCandidates[i].name, 20, electionInfo);
- }
- for (i=0;i<365;i++){
- fscanf(electionInfo, "%d", &voteHolder[i]);
- switch(voteHolder[i]){
- case 1:
- electionCandidates[0].votes++;
- break;
- case 2:
- electionCandidates[1].votes++;
- break;
- case 3:
- electionCandidates[2].votes++;
- break;
- case 4:
- electionCandidates[3].votes++;
- break;
- case 5:
- electionCandidates[4].votes++;
- break;
- case 6:
- electionCandidates[5].votes++;
- break;
- case 7:
- electionCandidates[6].votes++;
- break;
- default:
- spoiltVotes++;
- break;
- }
- }
- fclose(electionInfo);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement