Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

beginner question

Options
  • 23-09-2004 10:36pm
    #1
    Closed Accounts Posts: 272 ✭✭


    I've just started CS in Dit and I've been looking through our programming book. The book contains the following example:

    #include <stdio.h>
    main ()
    {
    printf ("Data type [align=center] Number of bytes\n"); [/align]
    printf ("
    [align=center]
    \n");[/align]
    printf ("char [align=center] %d\n", sizeof (char) );[/align]
    printf ("int [align=center] %d\n", sizeof (int) );[/align]
    printf ("short int [align=center]%d\n", sizeof (short) );[/align]
    printf ("long int [align=center] %d\n", sizeof (long) );[/align]
    printf ("float [align=center] %d\n", sizeof (float) );[/align]
    printf ("double [align=center] %d\n", sizeof (double) );[/align]
    }

    It then says, The output of this program when the compiler is used is:
    ......

    I'm using the Dev-C++ compiler and entered all that in and I got no errors. How do I get to see the results on the screen? I've pressed Run but something just flashes on the screen for a mili-second and goes.

    Thanks.


Comments

  • Registered Users Posts: 604 ✭✭✭Kai


    The problem is that the program is running fine and then the window closes straight away so you need to get it to keep the window open till you hit a key.

    i think you can put
    pause();

    at the end of the code to pause the screen. Or else try

    int anykey;

    scanf(anykey,%d);

    that will stop the program till you hit a key.


    Also i think Dev-C++ has a setting for leaving the window open after the program runs, see if you can find that.


  • Closed Accounts Posts: 272 ✭✭irish life


    Cheers for that Kai but the way I did it was putting the cursor at the end of the return statement, then clicking the Debug tag and "Run to cursor".


  • Closed Accounts Posts: 3,322 ✭✭✭Repli


    You can do two things
    - Drag the .exe file into a dos window and then hit enter
    - Add system("pause"); before the closing } in main


Advertisement