[c] How can I see an the output of my C programs using Dev-C++?

I'm looking to follow along with The C Programming Language (Second Addition) on a machine running Vista.

So far, I've found Dev-C++ the easiest IDE to do this in. However, I still have one problem. Whenever I run my compiled code, for example: a simple hello world program, it runs, but the console window just flickers on the screen, and I can't see the output.

How can I see an the output of my C programs using Dev-C++? I found a C++ specific solution, System("pause"), and a really ugly C solution, while looping fflush(stdout), but nothing nice and pretty.

This question is related to c dev-c++

The answer is


Add this to your header file #include and then in the end add this line : getch();


When a program is not showing or displaying an output on the screen, using system("pause"); is the solution to it on a Windows profile.


For Dev-C++, the bits you need to add are:-

At the Beginning

#include <stdlib.h>

And at the point you want it to stop - i.e. before at the end of the program, but before the final }

system("PAUSE");

It will then ask you to "Press any key to continue..."


The use of line system("PAUSE") will fix that problem and also include the pre processor directory #include<stdlib.h>.


i think you should link your project in console mode

just press Ctrl+h and in General tab select console.


Use #include conio.h

Then add getch(); before return 0;


The easiest thing to do is to run your program directly instead of through the IDE. Open a command prompt (Start->Run->Cmd.exe->Enter), cd to the folder where your project is, and run the program from there. That way, when the program exits, the prompt window sticks around and you can read all of the output.

Alternatively, you can also re-direct standard output to a file, but that's probably not what you are going for here.


Add a line getchar(); or system("pause"); before your return 0; in main function. It will work for you.


; It works...

#include <iostream>
using namespace std;
int main ()
{
   int x,y; // (Or whatever variable you want you can)

your required process syntax type here then;

   cout << result 

(or your required output result statement); use without space in getchar and other syntax.

   getchar();
}

Now you can save your file with .cpp extension and use ctrl + f 9 to compile and then use ctrl + f 10 to execute the program. It will show you the output window and it will not vanish with a second Until you click enter to close the output window.


You can open a command prompt (Start -> Run -> cmd, use the cd command to change directories) and call your program from there, or add a getchar() call at the end of the program, which will wait until you press Enter. In Windows, you can also use system("pause"), which will display a "Press enter to continue..." (or something like that) message.


I put a getchar() at the end of my programs as a simple "pause-method". Depending on your particular details, investigate getchar, getch, or getc


Well when you are writing a c program and want the output log to stay instead of flickering away you only need to import the stdlib.h header file and type "system("PAUSE");" at the place you want the output screen to halt.Look at the example here.The following simple c program prints the product of 5 and 6 i.e 30 to the output window and halts the output window.

#include <stdio.h>
#include <stdlib.h>
int main()
 {
      int a,b,c;
      a=5;b=6;
      c=a*b;
      printf("%d",c);
      system("PAUSE");
      return 0;
 }

Hope this helped.