Problems running .exe after compiling with gcc
Posted by Heide9095@reddit | learnprogramming | View on Reddit | 5 comments
Hi, I am a beginner in programming, but I am learning and willing to learn. I followed the simple "hello, world" program given in "the C Programming Language " 2nd ed book.
#include <stdio.h>
int main() {
printf("hello, world\n");
}
Thereafter I compiled it
gcc test.c -o test
Thereafter I located test.exe and ran it from the terminal
$ start test.exe
however a window flickers and disappears.
I found the .exe and ran it manually with the same result.
After some 'googling' I found similar cases online but in no case was the problem solved.
I am using windows 11, nvim and gcc through msys2.
Help is very much appreciated.
light_switchy@reddit
Lose the call to "start"; type just
test.exe
(assuming Windows) instead.FlightUpper5037@reddit
Try ./test.exe
desrtfx@reddit
The console instantly closes as soon as the program is finished. This is expected behavior and not a problem.
Just add a statement waiting for a keypress to keep the console open e.g.:
Heide9095@reddit (OP)
Thank you very much.
I did manage to basically find the same answer shortly after posting this, but with an alternative solution for keeping the window open.
: https://stackoverflow.com/questions/1864029/how-do-you-keep-the-console-from-closing-after-the-program-is-done-in-c
UncontroversialJuju@reddit
Code is running but at end of execution it closes the window. Try to google how you can keep the window open longer.