-2

Possible Duplicate:
C++ beginner, execution window disappears quickly

I am beginner at C programming. But when I compile the programm, a problem occurs. The compiler create a .exe for the program, but when I open it, it appears and disappears in a second.

This error can be stopped by adding

SYSTEM("PAUSE");

at end of the program. But it will create a

press any key to continue

at the end of program. What is the error of mine? Why the program appears and disappears in a hurry?

How do I stop it without adding the system() function? I'm using the GCC compiler.

Community
  • 1
  • 1
gokul
  • 29
  • 1
  • 5
  • 1
    Why shouldn't the program disappear in a hurry? :) – Pavan Manjunath Apr 06 '12 at 07:30
  • Learn from a better book and use a better IDE. – dreamlax Apr 06 '12 at 07:31
  • @PavanManjunath:i CANT SEE WHATS INSIDE IT because it terminates in a hurry just in 1 millisecond – gokul Apr 06 '12 at 07:32
  • @GokulKtp You haven't told the program to wait for you. Thats why it terminates. As you've already mentioned yourself, use something like `system("pAUSE")` , `getchar` etc to tell your program to wait for you – Pavan Manjunath Apr 06 '12 at 07:34
  • Many, many duplicates, e.g. [C++ beginner, execution window disappears quickly](http://stackoverflow.com/questions/9436108/c-beginner-execution-window-disappears-quickly) and [How can I get a Windows console to stay open?](http://stackoverflow.com/questions/482444/how-can-i-get-a-windows-console-to-stay-open) – Paul R Apr 06 '12 at 07:47

5 Answers5

3

That isn't an error. The program will terminate after finishing the code you programmed. If you want to input something try scanf for instance.

juergen d
  • 201,996
  • 37
  • 293
  • 362
1

Run the program form a dos window instead of double clinking if you dont want to add a pause or scanf

Sibster
  • 3,081
  • 21
  • 18
1

This is normal behaviour of a program. When it reaches its end, it has done what it had to do, and so it has nothing more to do. And this brings the OS to stop and delete its process.

Hubert Schölnast
  • 8,341
  • 9
  • 39
  • 76
0

It's not an error. The program executes and disappears when it's execution has finished.

0xc0de
  • 8,028
  • 5
  • 49
  • 75
  • If you want to stop the program after it has done its main intended purpose, add the `system()` call which is (logically) better than using input functions like `getchar()` or `scanf()`. – 0xc0de Apr 06 '12 at 07:36
-1

u can use an input function like gets() or getchar() or scanf() with no input variable instead of system()

Haywire
  • 858
  • 3
  • 14
  • 30
  • 4
    ******NEVER****** use `gets`. EVER. It is being removed from all standards (C, POSIX, etc.) – dreamlax Apr 06 '12 at 07:34
  • `gets` is no longer in the current C Standard (it was in [C99](http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf), it isn't in [C11](http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1570.pdf)). – pmg Apr 06 '12 at 09:49
  • oops! i knew that and still made the mistake! sorry!! – Haywire Apr 07 '12 at 05:43