我正在用gcc C编译器在Arch Linux中使用neovim,这就是我在.vimrc中使用的用于编译和运行的东西
map <F5> :w <CR> :!gcc % -o %< && ./%< <CR>
问题是我的代码可以正常运行,但是任何scanf()函数都不会提示输入,并且会在程序运行时被忽略。即使使用vim编译后,然后在单独的zsh终端中运行,它也允许我在使用以下命令运行代码时输入值./x
提前致歉,我是vim的新手,因此想使用它来加快我的工作流程。
以下代码显示了该问题:
#include <stdio.h>
int main()
{
char Team1[20];
char Team2[20];
int team1Score, team2Score;
printf("Please enter the name of team one: ");
scanf("%s", Team1);
printf("Please enter the name of team two: ");
scanf("%s", Team2);
printf("Please enter the score for %s: ", Team1);
scanf("%d", & team1Score);
printf("Please enter the score for %s: ", Team2);
scanf("%d", & team2Score);
if (team1Score > team2Score)
{
printf("%s scores 3 points and %s scores 0 points", Team1, Team2 );
}
else
if (team1Score < team2Score)
{
printf("%s scores 3 points and %s scores 0 points", Team2, Team1 );
}
else
{
printf("Both %s and %s score 1 point", Team1, Team2);
}
return 0;
}
故障可能不在您的程序中,而是vim执行它的方式。如果查看:!
命令文档,则可以看到以下内容:
该命令在连接到管道(不是终端)的非交互式外壳中运行。
非交互式外壳是指不允许输入用户命令的外壳。您的程序不会从终端读取scanf输入,而是从vim创建的管道读取。
如果您使用的是vim的最新版本(如果我是对的,则为8.0或更高版本)或neovim,则可以使用:term
命令打开终端。在该终端中,您将能够输入用户输入。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句