Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- // Counts the total number of votes
- int votes_cast (FILE* voteLines)
- {
- int count = 0;
- char readVote[100];
- while (fgets(readVote, 100, voteLines) != NULL)
- count++;
- return count;
- }
- // Counts how many votes were cast for the specified party by each constituency
- int votes_cast_in_constituency_party (FILE* votePerCon, char* con, char* party)
- {
- int count = 0;
- char lineOfText[100];
- while(fgets(lineOfText, 100, votePerCon) != NULL){
- if(strstr(lineOfText, con) != NULL && strstr(lineOfText, party) != NULL){
- count++;
- }
- }
- return count;
- }
- int main()
- {
- int voteLines = 0, votePerCon = 0;
- char con[20] = "The Shadows", party[20] = "Wizards";
- // Opens votes.txt file for reading
- FILE *votesTxt;
- votesTxt = fopen("votes.txt", "r");
- // Calls function that counts the total number of votes
- voteLines = votes_cast(votesTxt),
- printf("%d\n", voteLines);
- // Calls function that counts votes per constituency
- votePerCon = votes_cast_in_constituency_party(votesTxt, con, party),
- printf("%d\n", votePerCon);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement