#include <stdio.h>
int countCntyOccur (char cntyCodes[],int size);
int main(void) {
char cntyCodes[]= {'C','c','D','d','G','g','L','l','T','t','W','w'};
countCntyOccur(cntyCodes,12);
return 0;
}
int countCntyOccur (char cntyCodes[],int size){
int totalCorkCodes=0;
int totalDublinCodes=0;
int totalGalwayCodes=0;
int totalLimerickCodes=0;
int totalTiperaryCodes=0;
int totalWaterfordCodes=0;
int totalInvalidCountryCodes=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:
totalInvalidCountryCodes+=1;
}
}
printf("The grade is: %i\n", totalCorkCodes
); // struct countryTotals{
// int totalCorkCodes;
// int totalDublinCodes;
// int totalGalwayCodes;
// int totalLimerickCodes;
// int totalTiperaryCodes;
// int totalWaterfordCodes;
// int totalInvalidCountryCodes;
// }
// return countryTotals;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgY291bnRDbnR5T2NjdXIgKGNoYXIgY250eUNvZGVzW10saW50IHNpemUpOwoKaW50IG1haW4odm9pZCkgewoJY2hhciBjbnR5Q29kZXNbXT0geydDJywnYycsJ0QnLCdkJywnRycsJ2cnLCdMJywnbCcsJ1QnLCd0JywnVycsJ3cnfTsKICAgIGNvdW50Q250eU9jY3VyKGNudHlDb2RlcywxMik7CglyZXR1cm4gMDsKfQoKCmludCBjb3VudENudHlPY2N1ciAoY2hhciBjbnR5Q29kZXNbXSxpbnQgc2l6ZSl7CgogICAgaW50IHRvdGFsQ29ya0NvZGVzPTA7CiAgICBpbnQgdG90YWxEdWJsaW5Db2Rlcz0wOwogICAgaW50IHRvdGFsR2Fsd2F5Q29kZXM9MDsKICAgIGludCB0b3RhbExpbWVyaWNrQ29kZXM9MDsKICAgIGludCB0b3RhbFRpcGVyYXJ5Q29kZXM9MDsKICAgIGludCB0b3RhbFdhdGVyZm9yZENvZGVzPTA7CiAgICBpbnQgdG90YWxJbnZhbGlkQ291bnRyeUNvZGVzPTA7CgoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgc2l6ZTsgaSsrKSB7CiAgICAgICAgLy8gU3dpdGNoIHN0YXRlbWVudAogICAgICAgIHN3aXRjaCAoY250eUNvZGVzW2ldKSB7CiAgICAgICAgY2FzZSAnQyc6CiAgICAgICAgY2FzZSAnYyc6CiAgICAgICAgICAgIHRvdGFsQ29ya0NvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnRCc6CiAgICAgICAgY2FzZSAnZCc6CiAgICAgICAgICAgIHRvdGFsRHVibGluQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwoKICAgICAgICBjYXNlICdHJzoKICAgICAgICBjYXNlICdnJzoKICAgICAgICAgICAgdG90YWxHYWx3YXlDb2Rlcys9MTsKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0wnOgogICAgICAgIGNhc2UgJ2wnOgogICAgICAgICAgICB0b3RhbExpbWVyaWNrQ29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIGNhc2UgJ1QnOgogICAgICAgIGNhc2UgJ3QnOgogICAgICAgICAgICB0b3RhbFRpcGVyYXJ5Q29kZXMrPTE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIAogICAgICAgIGNhc2UgJ1cnOgogICAgICAgIGNhc2UgJ3cnOgogICAgICAgICAgICB0b3RhbFdhdGVyZm9yZENvZGVzKz0xOwogICAgICAgICAgICBicmVhazsKICAgICAgICAKICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICB0b3RhbEludmFsaWRDb3VudHJ5Q29kZXMrPTE7CiAgICAgICAgfQoKICAgIH0KICAgIHByaW50ZigiVGhlIGdyYWRlIGlzOiAlaVxuIiwgdG90YWxDb3JrQ29kZXMpOwogICAgLy8gc3RydWN0IGNvdW50cnlUb3RhbHN7CiAgICAvLyAgICAgaW50IHRvdGFsQ29ya0NvZGVzOwogICAgLy8gICAgIGludCB0b3RhbER1YmxpbkNvZGVzOwogICAgLy8gICAgIGludCB0b3RhbEdhbHdheUNvZGVzOwogICAgLy8gICAgIGludCB0b3RhbExpbWVyaWNrQ29kZXM7CiAgICAvLyAgICAgaW50IHRvdGFsVGlwZXJhcnlDb2RlczsKICAgIC8vICAgICBpbnQgdG90YWxXYXRlcmZvcmRDb2RlczsKICAgIC8vICAgICBpbnQgdG90YWxJbnZhbGlkQ291bnRyeUNvZGVzOyAgIAogICAgLy8gfQogICAgLy8gcmV0dXJuIGNvdW50cnlUb3RhbHM7Cgp9