为什么在Vim中运行C代码会跳过scanf()?
我在ArchLinux和gcc C编译器中使用neovim,这就是我在.vimrc中编译和运行的内容为什么在Vim中运行C代码会跳过scanf()?,c,linux,gcc,vim,scanf,C,Linux,Gcc,Vim,Scanf,我在ArchLinux和gcc C编译器中使用neovim,这就是我在.vimrc中编译和运行的内容 map:w:!gcc%-o%团队2核心) { printf(“%s得3分,%s得0分”,第1组,第2组); } 其他的 if(团队1核心
map:w:!gcc%-o%<&/%
问题是我的代码运行正常,但是任何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;
}
#包括
int main()
{
char Team1[20];
char-Team2[20];
int team1Score、team2Score;
printf(“请输入第一组的名称:”);
scanf(“%s”,第1组);
printf(“请输入第二组的名称:”);
scanf(“%s”,第2组);
printf(“请输入%s:,Team1的分数);
scanf(“%d”和team1Score);
printf(“请输入%s:,Team2的分数);
scanf(“%d”和&team2Score);
如果(团队1核心>团队2核心)
{
printf(“%s得3分,%s得0分”,第1组,第2组);
}
其他的
if(团队1核心<团队2核心)
{
printf(“%s得3分,%s得0分”,第2组,第1组);
}
其他的
{
printf(“两个%s和%s都得1分”,第1组,第2组);
}
返回0;
}
故障可能不在程序中,而是vim执行它的方式。如果您查看的文档:代码>命令,然后您可以看到以下内容:
该命令在连接到管道(而不是管道)的非交互式外壳中运行
终端)
非交互式shell指不允许输入用户命令的shell。您的程序不会从终端读取scanf输入,而是从vim创建的管道读取
如果您使用的是最新版本的vim(8.0或更高版本,如果我是对的)或neovim,则可以使用:term
命令打开终端。在该终端中,您可以输入用户输入。向我们展示您的(最小)程序可能会有所帮助。可能您在打印结束时缺少了一些\n
,并且在等待输入之前输出没有刷新。Vim只是一个文本编辑器。它不会影响程序的执行方式。问题出在代码中的某个地方。@DeiDei我同意,但正如我所说的,代码在zsh shell和bash中按预期工作,而不是在运行时vim@Tom1:代码属于问题,而非场外。请发布您的实际输入和结果输出。否则,此问题与stackoverflow无关