简体   繁体   English

为什么我的 C 代码在终端中运行,但在使用 Code Runner 的 VS 代码中却没有?

[英]Why does my C code run in terminal but not in VS Code using Code Runner?

During a class we started learning C, all of the tasks that I was given I managed to do expect when the scanf tasks came, after I couldn't make it work, I copied the code from the professor and I still couldn't make it work.在 class 期间,我们开始学习 C,当 scanf 任务到来时,我设法完成的所有任务,在我无法使其工作后,我从教授那里复制了代码,但我仍然无法这行得通。 I am using vs code, code runner extension and gcc on ubuntu linux.我在 ubuntu linux 上使用 vs 代码、代码运行程序扩展和 ZE0D511356C9DCF3B3Z。

Here is the code:这是代码:

#include <stdio.h>
#include <stdlib.h>

int main()
 {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    printf("Zbir je %d\n", a+b);
    return 0;
}

Here is the output, it does not stop untill I press the stop button: Output这是output,直到我按下停止按钮才停止: Output

The code looks fine.代码看起来不错。 You might want to change a setting in vs-code to run code in an integrated terminal.您可能想要更改 vs-code 中的设置以在集成终端中运行代码。 Go to File ->Preference -> Settings. Go 到文件 -> 首选项 -> 设置。 Add the following code:添加以下代码:

{
    "code-runner.runInTerminal": true
}

I tried running it in my machine and it ran correctly.我尝试在我的机器上运行它并且它运行正确。

I can tell from the picture that you are using vscode and running it with an extension.我可以从图片中看出您正在使用 vscode 并使用扩展程序运行它。 The problem must be there问题一定在那里

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM