gpt4 book ai didi

c - C语言读取用户输入

转载 作者:行者123 更新时间:2023-11-30 20:06:59 28 4
gpt4 key购买 nike

如何提示用户输入国家/地区名称(例如 Malaysia),以将变量 country1 替换为 Malaysia

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
writeRecipe (int fd)
{
readData ();
char country1[LINE_MAX] = "China";
static char* line1 = "Starting Country Search Client ...\n\n\n";
static char* line2 = "**********************************************";
static char* line3 = "Welcome to the Country Info Directory Service!";
static char* line4 = "**********************************************\n\n";

write (fd, line1, strlen (line1) + 1); /* Write first line */
write (fd, line2, strlen (line2) + 1); /* Write second line */
write (fd, line3, strlen (line3) + 1); /* Write third line */
write (fd, line4, strlen (line4) + 1); /* Write fourth line */


puts("Please enter country > ");
fgets(country1, sizeof country1,stdin);
printf ("\n%s Capital : %s\n", country1, getCapital (country1));
printf ("%s Currency Code : %s\n", country1, getCurrencyCode (country1));
}

最佳答案

How do i prompt user to enter a country name such as Malaysia

方法如下:

puts("Please enter a country name:");

现在,如果您想实际读取用户输入:

char buf[LINE_MAX] = "China";
fgets(buf, sizeof buf, stdin);

不要做任何其他事情。严重地。这是安全、简单、美好的。

关于c - C语言读取用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18129043/

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