Search This Blog

Friday, August 19, 2011

storing a string to print later

I’m trying to determine then print the country of origin of a product based on its bar-code.

I have isolated that part of the bar-code and stored it as countryCode, now what i am trying to do is determine its country then store the country name as a string so i can print it out at the end with other details of the product. right now i am getting random character that make no sense


My code for storing the country name is


// Determine country

if (countryCode == 850){

char country[50] = {“Cuba”};

} else if (countryCode == 858){

char country[50] ={“Slovakia”};

} else if (countryCode == 859){

char country[50] ={“Czech Republic”};

} else if (countryCode == 860){

char country[50] ={“Serbia”};

} else if (countryCode == 865){

char country[50] ={“Mongolia”};

} else if (countryCode == 867){

char country[50] ={“North Korea”};

} else if (countryCode >= 868 && countryCode <= 869){

char country[50] ={“Turkey”};

} else if (countryCode >= 870 && countryCode <= 879){

char country[50] ={“Netherlands”};

} else if (countryCode == 880){

char country[50] ={“South Korea”};

} else if (countryCode == 884){

char country[50] ={“Cambodia”};

} else if (countryCode == 885){

char country[50] ={“Thailand”};

} else if (countryCode == 888){

char country[50] ={“Singapore”};

} else if (countryCode == 890){

char country[50] ={“India”};

} else if (countryCode == 893){

char country[50] ={“Vietnam”};

} else if (countryCode == 896){

char country[50] ={“Pakistan”};

} else if (countryCode == 899){

char country[50] ={“Indonesia”};

} else if (countryCode >= 900 && countryCode <= 919){

char country[50] ={“Austria”};

} else if (countryCode >= 930 && countryCode <= 939){

char country[50] ={“Australia”};

} else if (countryCode >= 940 && countryCode <= 949){

char country[50] ={“New Zealand”};

} else if (countryCode == 950){

char country[50] ={“Global Office”};

} else if (countryCode == 955){

char country[50] ={“Malaysia”};

} else if (countryCode == 958){

char country[50] ={“Macau”};

} else if (countryCode >= 977 && countryCode <= 979){

char country[50] ={“ISBN”};

} else {

char country[50] ={“country no recognised”};


my print statement is


printf(“Country code: %ld (%s)n”, countryCode, country);


which should print as





Country code: 955 (Macau)




thanks

http://bit.ly/pxIynJ

No comments:

Post a Comment