Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

beginner question

  • 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, Registered Users 2 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