Thanks, for all that help on the first one, but I ran into another problem. The code will only read the first letter of the country and compare that. This is a problem because some of the country's start with the same first letter. Wright now all I have to do is enter a capital letter that one of the country's begen with and it will give its code. How do you compare the whole word?
#include <stdio.h>
struct dialing_code {
char country[19]; /*would changing this to a pointer be
int code; beter *country ? */
};
int main(void)
{
const struct dialing_code country_codes[] = {{"Argentina", 54},{"Bangladesh", 880},{"Brazil", 55},{"China", 86},{"Colombia", 57},{"Ethiopia", 251}};
int i;
char c;
printf("Enter a country you want the dialing code for: "
scanf("%c", &c);
if(c>=97 && c<=122)
c-=32;
for(i=0;i<6;i++)
{
if(c== country_codes.country[0])
printf("%d\n", country_codes.code);
}
return 0;
}
Thanks again for your help!!
#include <stdio.h>
struct dialing_code {
char country[19]; /*would changing this to a pointer be
int code; beter *country ? */
};
int main(void)
{
const struct dialing_code country_codes[] = {{"Argentina", 54},{"Bangladesh", 880},{"Brazil", 55},{"China", 86},{"Colombia", 57},{"Ethiopia", 251}};
int i;
char c;
printf("Enter a country you want the dialing code for: "
scanf("%c", &c);
if(c>=97 && c<=122)
c-=32;
for(i=0;i<6;i++)
{
if(c== country_codes.country[0])
printf("%d\n", country_codes.code);
}
return 0;
}
Thanks again for your help!!