作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
void capital() //print the capitals of the choosen countries
{
system("cls");
struct country
{
char name[40];
char capital[40];
};
struct country cont_list[100]=
{
"amman","jordan",
"amsterdam","nertherlands",
"athens","greece",
"bangkok","thailand",
"beijing","china",
"berlin","germany",
"cairo","egypt",
"canberra","australia",
"copenhagen","denmark",
"dhaka","bangladesh",
"doha","qatar",
"dublin","ireland",
"helsinki","finland",
"jakarta","indonesia",
"kabul","afghanistan",
"kingston","jamaica",
"kuala lumpur","malaysia",
"london","unitedkingdom",
"lisbon","portugal",
"madrid","spain",
"manila","philippines",
"mexico city","mexico",
"moscow","russia",
"nairobi","kenya",
"nassau","bahamas",
"new delhi","india",
"ottawa","canada",
"oslo","norway",
"paris","france",
"prague","czech republic",
"pretoria","africa",
"pristina","kosovo",
"pyonyang","north korea",
"riyadh","saudi arabia",
"rome","italy",
"colombo","sri lanka",
"santiago","chile",
"seoul","south korea",
"singapore","singapore",
"sofia","bulgaria",
"stockholm","sweden",
"suva","fiji",
"taipei","taiwan",
"tashkent","uzbekistan",
"tbilisi","georgia",
"tehran","iran",
"tirana","albania",
"tokyo","japan",
"tripoli","libya",
"tunis","tunisia",
"ulaanbaatar","mongolia",
"vienna","austria",
"vientiane","laos",
"warsaw","poland",
"washington d.c","united states of america",
"wellington","new zealand",
"zagreb","crotia",
};
int i,choice;
int pos;
char inval[20];
system("cls");
printf("Enter the name of the Country : ");
gets(inval);
pos=-1;
for(i=0;i<=50;i++)
{
if(strcmp(inval,cont_list[i].name)==0)
pos=i;
}
if(pos>-1)
{
printf("capital= ");
printf("%x", cont_list[pos].capital);
getch();
}
else
printf("\n\t Sorry, Country not in database");
askover();
system("pause");
// End function
}
编写一个交互式菜单驱动程序 C 程序,该程序将接受国家/地区名称作为输入并显示相应的大写字母,反之亦然。设计程序,使其重复执行,直到输入单词 End 作为输入。请添加更多国家/地区列表(至少 50 个)。
最佳答案
如果您的问题是比较字符串,您可能需要切换structcountry
内变量的顺序。也就是说,安曼是约旦的首都,而不是相反。否则 strcmp
将永远不会返回 0。
关于c - 在交互式 C 控制台应用程序中输入国家/地区后,打印大写名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33669331/
我是一名优秀的程序员,十分优秀!