how to stop a program and see what it prints

Discussion in 'Programmer's Corner' started by EngIntoHW, Oct 19, 2012.

  1. EngIntoHW

    Thread Starter Member

    Apr 24, 2010
    128
    0
    I'm programming in C language.

    I use printf function and when I run the program, I cannot see what it prints.

    What would be a proper way to hold the program at a desired point?

    Edit:
    I'm using Dev-C++ Compiler
     
    Last edited: Oct 19, 2012
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Which C compiler are you using?
     
  3. EngIntoHW

    Thread Starter Member

    Apr 24, 2010
    128
    0
    Dev-C++ Compiler
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Try this. I will also strongly recommend that you learn how to use the debugger. Like setting break-points, add a watch, or do some single stepping. Many beginners think this is a waste of time. But trust me then I said this is a must. Try this Google search
    Code ( (Unknown Language)):
    1. #include <stdio.h>
    2.  
    3. int main()
    4. {
    5.   printf ("Press ENTER to continue.\n");
    6.   getchar (); // wait for input
    7.   return 0;
    8. }
    Code ( (Unknown Language)):
    1.  
    2. #include <stdlib.h>
    3.  
    4. int main()
    5. {
    6.   system ("pause"); // execute M$-DOS' pause command
    7.   return 0;
    8. }
    9.  
     
  5. EngIntoHW

    Thread Starter Member

    Apr 24, 2010
    128
    0
    works great, Thank you!
     
  6. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    That is not a good solution as it is dependant on some rather old code, better way is to start the command line and run the program from there instead of double clicking on it.
    Also the approach with pause won't help you when you have some console program like gcc which just blinks and dissapears, and you want to see result. Then command line is your only option as you can't change the program you are running.
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Maybe, but as I understand it. The OP is running the program from the compiler enviroment just to learn C. Then this method will work more than good.
     
Loading...