Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

C program ending after taking input in VS Code External Terminal

I made this changes in the executor map to run the program in the external termina: "code-runner.executorMap": { "cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe" }

The program did start to run in the external terminal but it ends after taking the input. Here is the simple C code:

#include<stdio.h>
int main()
{
    int x,y,l,a,b;
    printf("Enter the bottom left co-ordinates of the square: ");
    scanf(" %d %d", &x, &y);
    printf("Enter the length of the square: ");
    scanf(" %d", &l);
    printf("Enter the co-ordinates to be checked: ");
    scanf(" %d %d", &a, &b);
    if((a>=x && a<=(x+l)) && (b>=y && b<=(y+l))) //boundary limits for four sides of the square
    {
        printf("
%d,%d lies inside the square.", a,b);
    }
    else
    {
        printf("
%d,%d don't lie inside the square.", a,b);
    }
    return 0;   
}

enter image description here

The program then ends after taking the input. Please help me to solve this problem of VS Code.

question from:https://stackoverflow.com/questions/65896528/c-program-ending-after-taking-input-in-vs-code-external-terminal

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You program urns but the window will be closed because it will exit. You need to keep the window open after the program has ended:

{ "cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start /wait $fileNameWithoutExt.exe" }

The /wait option for the command start will run the command-prompt with the /k option which ensures that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...