#include <stdio.h>
struct countyTotals{
int totalCorkCodes;
int totalDublinCodes;
int totalGalwayCodes;
int totalLimerickCodes;
int totalTiperaryCodes;
int totalWaterfordCodes;
int totalInvalidCountryCodes;
};
struct countyTotals countCntyOccur (char cntyCodes[], int size);
int main(void) {
char cntyCodes[]= {'C','c','c','D','d','G','L','l','l','L','T','t','t','W','w','X'};
struct countyTotals countyFreqs = countCntyOccur(cntyCodes,16);
printf("Cork County: %i", countyFreqs.
totalCorkCodes); printf("Dublin County: %i", countyFreqs.
totalDublinCodes);
return 0;
}
struct countyTotals countCntyOccur(char cntyCodes[], int size){
int totalCorkCodes=0;
int totalDublinCodes=0;
int totalGalwayCodes=0;
int totalLimerickCodes=0;
int totalTiperaryCodes=0;
int totalWaterfordCodes=0;
int totalInvalidCountyCodes=0;
for (int i = 0; i < size; i++) {
// Switch statement
switch (cntyCodes[i]) {
case 'C':
case 'c':
totalCorkCodes+=1;
break;
case 'D':
case 'd':
totalDublinCodes+=1;
break;
case 'G':
case 'g':
totalGalwayCodes+=1;
break;
case 'L':
case 'l':
totalLimerickCodes+=1;
break;
case 'T':
case 't':
totalTiperaryCodes+=1;
break;
case 'W':
case 'w':
totalWaterfordCodes+=1;
break;
default:
totalInvalidCountyCodes+=1;
break;
}
}
// printf("The number of Cork codes is: %i\n", totalCorkCodes);
// printf("The number of Dublin codes is: %i\n", totalDublinCodes);
// printf("The number of Galway codes is: %i\n", totalGalwayCodes);
// printf("The number of Limerick codes is: %i\n", totalLimerickCodes);
// printf("The number of Tiperary codes is: %i\n", totalTiperaryCodes);
// printf("The number of Waterford codes is: %i\n", totalWaterfordCodes);
// printf("The number of invalid codes is: %i\n", totalInvalidCountyCodes);
struct countyTotals specificCountyTotals = {totalCorkCodes, totalDublinCodes, totalGalwayCodes,
totalLimerickCodes, totalTiperaryCodes,
totalWaterfordCodes, totalInvalidCountyCodes};
// printf("The output is: %i\n", specificCountyTotals);
return specificCountyTotals;
}
I2luY2x1ZGUgPHN0ZGlvLm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AgIGludCB0b3RhbFdhdGVyZm9yZENvZGVzPTA7CiAgICBpbnQgdG90YWxJbnZhbGlkQ291bnR5Q29kZXM9MDsKCgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsKICAgICAgICAvLyBTd2l0Y2ggc3RhdGVtZW50CiAgICAgICAgc3dpdGNoIChjbnR5Q29kZXNbaV0pIHsKICAgICAgICBjYXNlICdDJzoKICAgICAgICBjYXNlICdjJzoKICAgICAgICAgICAgdG90YWxDb3JrQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdEJzoKICAgICAgICBjYXNlICdkJzoKICAgICAgICAgICAgdG90YWxEdWJsaW5Db2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0cnOgogICAgICAgIGNhc2UgJ2cnOgogICAgICAgICAgICB0b3RhbEdhbHdheUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnTCc6CiAgICAgICAgY2FzZSAnbCc6CiAgICAgICAgICAgIHRvdGFsTGltZXJpY2tDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgY2FzZSAnVCc6CiAgICAgICAgY2FzZSAndCc6CiAgICAgICAgICAgIHRvdGFsVGlwZXJhcnlDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgCiAgICAgICAgY2FzZSAnVyc6CiAgICAgICAgY2FzZSAndyc6CiAgICAgICAgICAgIHRvdGFsV2F0ZXJmb3JkQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHRvdGFsSW52YWxpZENvdW50eUNvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CgogICAgfQogICAgLy8gcHJpbnRmKCJUaGUgbnVtYmVyIG9mIENvcmsgY29kZXMgaXM6ICVpXG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