0

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

Vukašin
  • 17
  • 8
  • Your code is fine. Try to run it from a terminal. The problem is within the way the code is run by vscode. – Jabberwocky Dec 09 '21 at 17:25
  • 1
    Please don't use pictures of text! You can't copy'n'paste it to try it out. As a new user here, take the [tour] and read [ask]. – Ulrich Eckhardt Dec 09 '21 at 17:27
  • @Jabberwocky It works from the terminal so yes the problem must be with vs code, but I would really like to keep using it and make it work. – Vukašin Dec 09 '21 at 17:37
  • I found the answer ! https://stackoverflow.com/a/68516851/17318989 – Vukašin Dec 09 '21 at 17:44

2 Answers2

3

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
}
bharats
  • 366
  • 2
  • 9
0

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. The problem must be there

enter image description here