我正在编写一个程序,可以在手动模式下从用户那里获取计算机细节。但是,我遇到了一些问题。
在这段代码中:
char choice = getc(stdin);
if (choice == 'y' || choice == 'Y')
{
config_file = fopen(config_file_loc, "w");
printf("%s", "Please enter the name of your distribution/OS: ");
fgets(distro_str, MAX_STRLEN, stdin);
fputs(distro_str, config_file);
fputs("\n", config_file);
printf("%s", "Please enter your architecture: ");
fgets(arch_str, MAX_STRLEN, stdin);
fputs(arch_str, config_file);
fputs("\n", config_file);
fclose(config_file);
}
在运行时,输入从“请输入您的发行版/操作系统的名称:”跳转到“请输入您的架构:”,将 distro_str 留空。
我试过刷新标准输入和标准输出,但没有奏效。
谢谢你的帮助。