Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.
I am using vs code, code runner extension and gcc on ubuntu linux.

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The code looks fine. You might want to change a setting in vs-code to run code in an integrated terminal.
Go to File ->Preference -> Settings. Add the following code:

{
    "code-runner.runInTerminal": true
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading