#include <stdio.h>
struct countyTotals{
int totalCorkCodes;
int totalDublinCodes;
int totalGalwayCodes;
int totalLimerickCodes;
int totalTiperaryCodes;
int totalWaterfordCodes;
int totalInvalidCountryCodes;
};
void 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'};
countCntyOccur(cntyCodes,16);
return 0;
}
void 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;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgY291bnR5VG90YWxzewogICAgICAgIGludCB0b3RhbENvcmtDb2RlczsKICAgICAgICBpbnQgdG90YWxEdWJsaW5Db2RlczsKICAgICAgICBpbnQgdG90YWxHYWx3YXlDb2RlczsKICAgICAgICBpbnQgdG90YWxMaW1lcmlja0NvZGVzOwogICAgICAgIGludCB0b3RhbFRpcGVyYXJ5Q29kZXM7CiAgICAgICAgaW50IHRvdGFsV2F0ZXJmb3JkQ29kZXM7CiAgICAgICAgaW50IHRvdGFsSW52YWxpZENvdW50cnlDb2RlczsgICAKfTsKCnZvaWQgY291bnRDbnR5T2NjdXIgKGNoYXIgY250eUNvZGVzW10sIGludCBzaXplKTsKCmludCBtYWluKHZvaWQpIHsKCgljaGFyIGNudHlDb2Rlc1tdPSB7J0MnLCdjJywnYycsJ0QnLCdkJywnRycsJ0wnLCdsJywnbCcsJ0wnLCdUJywndCcsJ3QnLCdXJywndycsJ1gnfTsKICAgIGNvdW50Q250eU9jY3VyKGNudHlDb2RlcywxNik7CiAgICAKCXJldHVybiAwOwp9CgoKdm9pZCBjb3VudENudHlPY2N1ciAoY2hhciBjbnR5Q29kZXNbXSwgaW50IHNpemUpewoKICAgIGludCB0b3RhbENvcmtDb2Rlcz0wOwogICAgaW50IHRvdGFsRHVibGluQ29kZXM9MDsKICAgIGludCB0b3RhbEdhbHdheUNvZGVzPTA7CiAgICBpbnQgdG90YWxMaW1lcmlja0NvZGVzPTA7CiAgICBpbnQgdG90YWxUaXBlcmFyeUNvZGVzPTA7CiAgICBpbnQgdG90YWxXYXRlcmZvcmRDb2Rlcz0wOwogICAgaW50IHRvdGFsSW52YWxpZENvdW50eUNvZGVzPTA7CgoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKSB7CiAgICAgICAgLy8gU3dpdGNoIHN0YXRlbWVudAogICAgICAgIHN3aXRjaCAoY250eUNvZGVzW2ldKSB7CiAgICAgICAgY2FzZSAnQyc6CiAgICAgICAgY2FzZSAnYyc6CiAgICAgICAgICAgIHRvdGFsQ29ya0NvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnRCc6CiAgICAgICAgY2FzZSAnZCc6CiAgICAgICAgICAgIHRvdGFsRHVibGluQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdHJzoKICAgICAgICBjYXNlICdnJzoKICAgICAgICAgICAgdG90YWxHYWx3YXlDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0wnOgogICAgICAgIGNhc2UgJ2wnOgogICAgICAgICAgICB0b3RhbExpbWVyaWNrQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIGNhc2UgJ1QnOgogICAgICAgIGNhc2UgJ3QnOgogICAgICAgICAgICB0b3RhbFRpcGVyYXJ5Q29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIGNhc2UgJ1cnOgogICAgICAgIGNhc2UgJ3cnOgogICAgICAgICAgICB0b3RhbFdhdGVyZm9yZENvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICB0b3RhbEludmFsaWRDb3VudHlDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQoKICAgIH0KICAgIC8vIHByaW50ZigiVGhlIG51bWJlciBvZiBDb3JrIGNvZGVzIGlzOiAlaVxuIiwgdG90YWxDb3JrQ29kZXMpOwogICAgLy8gcHJpbnRmKCJUaGUgbnVtYmVyIG9mIER1YmxpbiBjb2RlcyBpczogJWlcbiIsIHRvdGFsRHVibGluQ29kZXMpOwogICAgLy8gcHJpbnRmKCJUaGUgbnVtYmVyIG9mIEdhbHdheSBjb2RlcyBpczogJWlcbiIsIHRvdGFsR2Fsd2F5Q29kZXMpOwogICAgLy8gcHJpbnRmKCJUaGUgbnVtYmVyIG9mIExpbWVyaWNrIGNvZGVzIGlzOiAlaVxuIiwgdG90YWxMaW1lcmlja0NvZGVzKTsKICAgIC8vIHByaW50Zig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