如何提示用户输入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));
}
答案 0 :(得分:3)
如何提示用户输入国家名称,例如马来西亚
这是:
puts("Please enter a country name:");
现在,如果您想实际读取用户输入:
char buf[LINE_MAX] = "China";
fgets(buf, sizeof buf, stdin);
不要做任何其他事情。认真。这是安全,简单和美好的。