#include <stdio.h>
struct countyTotals
{
int totalCorkCodes;
int totalDublinCodes;
int totalGalwayCodes;
int totalLimerickCodes;
int totalTiperaryCodes;
int totalWaterfordCodes;
int totalInvalidCountryCodes;
};
// add function block comments
struct countyTotals freqOfIrishCounties(char countyArrayList[], int size)
{
struct countyTotals myCountyTotals = {0,0,0,0,0,0,0}; // holds the country counts
// and initializes them to zero
// Review each of the county codes in the array
for(int i = 0; i < size; i++)
{
switch (countyArrayList[i]) //Structure variable countyArrayList
{
case 'C': // Cork uppercase and lowercase accepted
case 'c':
myCountyTotals.totalCorkCodes++; // add count if in category
break; //signify end of cases
case 'D': // Dublin uppercase and lowercase accepted
case 'd':
myCountyTotals.totalDublinCodes++; // add count if in category
break;
case 'G': // Galway uppercase and lowercase accepted
case 'g':
myCountyTotals.totalGalwayCodes++; // add count if in category
break;
case 'L': // Limerick uppercase and lowercase accepted
case 'l':
myCountyTotals.totalLimerickCodes++; // add count if in category
break;
case 'T': // Tipperary uppercase and lowercase accepted
case 't':
myCountyTotals.totalTiperaryCodes++; // add count if in category
break;
case 'W': // Waterford uppercase and lowercase accepted
case 'w':
myCountyTotals.totalWaterfordCodes++; // add count if in category
break;
default: // Invalid country codes
myCountyTotals.totalInvalidCountryCodes++; // add count if in category
break;
} // switch
} // for
return (myCountyTotals);
} // freqOfIrishCounties
int main(void) {
char counties[] = {'c', 'C', 'd', 'D', 'g', 'G', 'L', 'l', 'T', 't', 'W', 'w', 'r', 'j', 'm'};
int size = sizeof(counties) / sizeof(counties[0]); // define size of array
struct countyTotals totals = freqOfIrishCounties(counties, size); // Store results from countytotals
printf("Cork codes: %d\n", totals.
totalCorkCodes); //Print Cork total stored printf("Dublin codes : %d\n", totals.
totalDublinCodes); //Print Dublin total stored printf("Galway codes : %d\n", totals.
totalGalwayCodes); //Print Galway total stored printf("Limerick codes : %d\n", totals.
totalLimerickCodes); //Print Limerick total stored printf("Tipperary codes : %d\n", totals.
totalTiperaryCodes); //Print Tipperary total stored printf("Waterford codes : %d\n", totals.
totalWaterfordCodes); //Print Waterford total stored printf("Invalid codes : %d\n", totals.
totalInvalidCountryCodes); //Print Invalid total stored
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgY291bnR5VG90YWxzCnsKICAgIGludCB0b3RhbENvcmtDb2RlczsKICAgIGludCB0b3RhbER1YmxpbkNvZGVzOwogICAgaW50IHRvdGFsR2Fsd2F5Q29kZXM7CiAgICBpbnQgdG90YWxMaW1lcmlja0NvZGVzOwogICAgaW50IHRvdGFsVGlwZXJhcnlDb2RlczsKICAgIGludCB0b3RhbFdhdGVyZm9yZENvZGVzOwogICAgaW50IHRvdGFsSW52YWxpZENvdW50cnlDb2RlczsKfTsKICAgCi8vIGFkZCBmdW5jdGlvbiBibG9jayBjb21tZW50cwpzdHJ1Y3QgY291bnR5VG90YWxzIGZyZXFPZklyaXNoQ291bnRpZXMoY2hhciBjb3VudHlBcnJheUxpc3RbXSwgaW50IHNpemUpCnsKCiAgICBzdHJ1Y3QgY291bnR5VG90YWxzIG15Q291bnR5VG90YWxzID0gezAsMCwwLDAsMCwwLDB9OyAgLy8gaG9sZHMgdGhlIGNvdW50cnkgY291bnRzCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gYW5kIGluaXRpYWxpemVzIHRoZW0gdG8gemVybwoKICAgIC8vIFJldmlldyBlYWNoIG9mIHRoZSBjb3VudHkgY29kZXMgaW4gdGhlIGFycmF5CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKQogICAgewogICAgICAgIAogICAgICAgIHN3aXRjaCAoY291bnR5QXJyYXlMaXN0W2ldKSAvL1N0cnVjdHVyZSB2YXJpYWJsZSBjb3VudHlBcnJheUxpc3QKICAgICAgICB7CgogICAgICAgICAgICBjYXNlICdDJzogLy8gQ29yayB1cHBlcmNhc2UgYW5kIGxvd2VyY2FzZSBhY2NlcHRlZAogICAgICAgICAgICBjYXNlICdjJzoKICAgICAgICAgICAgICAgIG15Q291bnR5VG90YWxzLnRvdGFsQ29ya0NvZGVzKys7IC8vIGFkZCBjb3VudCBpZiBpbiBjYXRlZ29yeQogICAgICAgICAgICAgICAgYnJlYWs7IC8vc2lnbmlmeSBlbmQgb2YgY2FzZXMKCiAgICAgICAgICAgIGNhc2UgJ0QnOiAvLyBEdWJsaW4gdXBwZXJjYXNlIGFuZCBsb3dlcmNhc2UgYWNjZXB0ZWQKICAgICAgICAgICAgY2FzZSAnZCc6CiAgICAgICAgICAgICAgICBteUNvdW50eVRvdGFscy50b3RhbER1YmxpbkNvZGVzKys7IC8vIGFkZCBjb3VudCBpZiBpbiBjYXRlZ29yeQogICAgICAgICAgICAgICAgYnJlYWs7CgogICAgICAgICAgICBjYXNlICdHJzogLy8gR2Fsd2F5IHVwcGVyY2FzZSBhbmQgbG93ZXJjYXNlIGFjY2VwdGVkCiAgICAgICAgICAgIGNhc2UgJ2cnOgogICAgICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxHYWx3YXlDb2RlcysrOyAvLyBhZGQgY291bnQgaWYgaW4gY2F0ZWdvcnkKICAgICAgICAgICAgICAgIGJyZWFrOyAKCiAgICAgICAgICAgIGNhc2UgJ0wnOiAvLyBMaW1lcmljayB1cHBlcmNhc2UgYW5kIGxvd2VyY2FzZSBhY2NlcHRlZAogICAgICAgICAgICBjYXNlICdsJzoKICAgICAgICAgICAgICAgIG15Q291bnR5VG90YWxzLnRvdGFsTGltZXJpY2tDb2RlcysrOyAvLyBhZGQgY291bnQgaWYgaW4gY2F0ZWdvcnkKICAgICAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICAgICAgY2FzZSAnVCc6IC8vIFRpcHBlcmFyeSB1cHBlcmNhc2UgYW5kIGxvd2VyY2FzZSBhY2NlcHRlZAogICAgICAgICAgICBjYXNlICd0JzoKICAgICAgICAgICAgICAgIG15Q291bnR5VG90YWxzLnRvdGFsVGlwZXJhcnlDb2RlcysrOyAvLyBhZGQgY291bnQgaWYgaW4gY2F0ZWdvcnkKICAgICAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICAgICAgY2FzZSAnVyc6IC8vIFdhdGVyZm9yZCB1cHBlcmNhc2UgYW5kIGxvd2VyY2FzZSBhY2NlcHRlZAogICAgICAgICAgICBjYXNlICd3JzoKICAgICAgICAgICAgICAgIG15Q291bnR5VG90YWxzLnRvdGFsV2F0ZXJmb3JkQ29kZXMrKzsgLy8gYWRkIGNvdW50IGlmIGluIGNhdGVnb3J5CiAgICAgICAgICAgICAgICBicmVhazsKCiAgICAgICAgICAgIGRlZmF1bHQ6IC8vIEludmFsaWQgY291bnRyeSBjb2RlcwogICAgICAgICAgICAgICAgbXlDb3VudHlUb3RhbHMudG90YWxJbnZhbGlkQ291bnRyeUNvZGVzKys7IC8vIGFkZCBjb3VudCBpZiBpbiBjYXRlZ29yeQogICAgICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIH0gLy8gc3dpdGNoCiAgICB9IC8vIGZvcgoKICAgIHJldHVybiAobXlDb3VudHlUb3RhbHMpOwoKfSAvLyBmcmVxT2ZJcmlzaENvdW50aWVzCgppbnQgbWFpbih2b2lkKSB7CiAgICBjaGFyIGNvdW50aWVzW10gPSB7J2MnLCAnQycsICdkJywgJ0QnLCAnZycsICdHJywgJ0wnLCAnbCcsICdUJywgJ3QnLCAnVycsICd3JywgJ3InLCAnaicsICdtJ307CiAgICBpbnQgc2l6ZSA9IHNpemVvZihjb3VudGllcykgLyBzaXplb2YoY291bnRpZXNbMF0pOyAgLy8gZGVmaW5lIHNpemUgb2YgYXJyYXkKCiAgICBzdHJ1Y3QgY291bnR5VG90YWxzIHRvdGFscyA9IGZyZXFPZklyaXNoQ291bnRpZXMoY291bnRpZXMsIHNpemUpOyAvLyBTdG9yZSByZXN1bHRzIGZyb20gY291bnR5dG90YWxzCgogICAgcHJpbnRmKCJDb3JrIGNvZGVzOiAlZFxuIiwgdG90YWxzLnRvdGFsQ29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