gpt4 book ai didi

c - 在交互式 C 控制台应用程序中输入国家/地区后,打印大写名称

转载 作者:行者123 更新时间:2023-11-30 21:29:10 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com