i want to write a simple country code program. the program will ask the user to enter a country code. if the country code number matches to the struct then it gives out a result
if the user enters a country code which is not listed in the structure then an error message shows
when i write the correct country code the error message shows up. can someone help tell me where i have made a mistake in my code
Code:
#include <stdio.h>
#include <stdlib.h>
struct dialing_code {
char *country;
int code;
};
const struct dialing_code country_codes[]=
{ {"Argentina", 54}, {"Bangladesh", 880},
{"Brazil", 55}, {"Colombia", 57},
};
int main (void)
{
int code, i;
printf("Enter countrycode: ");
scanf("%d", &code);
if (country_codes[i].code==code) {
for (i=0; i<sizeof(country_codes)/sizeof(country_codes[0]); i++) {
printf("Country code %d is for %s", code, country_codes[i].country);
printf("\n");
}
}
else printf("Error\n");
return 0;
}