This is normal and even expected.
The prompt is open while your program is running, at the end it closes.
You can create forms of it not close immediately, it is quite common to use the function getchar()
as a test, before the return
of main
, so the program awaits the key ENTER no pressure to close:
#include <stdio.h>
int main(void) {
printf("Hello world\n");
getchar();
return 0;
}
With this, the data will be displayed at the prompt, but the function getchar
going hold on the execution.
See online: https://repl.it/repls/MedicalCriticalExperiments
You may end up finding examples that use system("pause")
, this will also hold running the program, but it will only work on Windows.
By any chance is he running the program and closing the screen? If you put to the end a reading instruction of type:
printf("Tecle algo para encerrar: "); gets(x);
.– anonimo