Code:
#include <stdio.h>
#include <string.h>
struct dialing_code {
char *country;
int code;
};
int main() {
const struct dialing_code country_code[] = {
{"Argentina", 54},
{"Bangladesh", 880},
{"Brazil", 55},
{"China", 86},
{"Colombia", 57},
{"Egypt", 20},
{"Ethiopia", 251},
{"France", 33},
{"Germany", 49},
{"India", 91},
{"Indonesia", 62},
{"Iran", 98},
{"Italy", 39},
{"Japan", 81},
};
char find_country[100];
int i;
int num_codes = 14;
printf("Program will give country dialing code\n");
printf("Input a country name to look up code : ");
scanf( "%s", find_country );
for ( i = 0 ; i < num_codes ; i++ ) {
if ( strcmp( find_country, country_code[i].country) == 0 ) {
printf( "Code for %s is %d\n",
country_code[i].country, country_code[i].code );
break;
}
}
return 0;
}