Question
C Programing: Finish the PrintCountryNames() function to print all country names in the list. #include #include #include const int MAX_COUNTRY_NAME_LENGTH = 50; typedef struct CountryTvWatch_struct
C Programing: Finish the PrintCountryNames() function to print all country names in the list.
#include
const int MAX_COUNTRY_NAME_LENGTH = 50;
typedef struct CountryTvWatch_struct { char countryName[50]; int tvMinutes; } CountryTvWatch;
void PrintCountryNames(CountryTvWatch ctryList[], int numCountries) { printf("FIXME: Finish PrintCountryNames()"); return; }
int main(void) { // Source: www.statista.com, 2010 const int NUM_COUNTRIES = 4;
CountryTvWatch countryList[NUM_COUNTRIES]; char countryToFind[MAX_COUNTRY_NAME_LENGTH]; bool countryFound = false; int i = 0; strcpy(countryList[0].countryName, "Brazil"); countryList[0].tvMinutes = 222; strcpy(countryList[1].countryName, "India"); countryList[1].tvMinutes = 119; strcpy(countryList[2].countryName, "U.K."); countryList[2].tvMinutes = 242; strcpy(countryList[3].countryName, "U.S.A."); countryList[3].tvMinutes = 283; printf("Enter country name: "); scanf("%s", countryToFind); countryFound = false; for (i = 0; i < NUM_COUNTRIES; ++i) { // Find country's index if (strcmp(countryList[i].countryName, countryToFind) == 0) { countryFound = true; printf("People in %s watch ", countryToFind); printf("%d minutes of TV daily. ", countryList[i].tvMinutes); } } if (!countryFound) { printf("Country not found, try again. "); printf("Valid countries: "); PrintCountryNames(countryList, NUM_COUNTRIES); } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started