Thread: My first program trouble

  1. #1
    Registered User
    Join Date
    Jul 2006

    My first program trouble

    I'm using Dev-C++ and am using C. I just started pretty much, but I keep having this problem. Basically I am making the "Hello World" program, and this is the code I use

    #include <stdio.h>
    int main()
        printf("Hello World\n");
        return 0;
    I then compile it (i think the linking is automatic), save it in my local documents, but then when I open it, it looks like a dos window that opens and closes really quickly. I save it as Hello.c

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    When I run my console application, the black window flashes a bit then closes automatically. How can I see the output of my program?

    Your program does exactly what you tell it to do, and you didn't ask it to wait before closing. You can add a command to wait for keyboard input before the program exits (e.g. before the return from main). A very simple example is system("pause"); which executes the "pause" system command (portability note: this only works in Windows and DOS); you need to #include <cstdlib> (or #include <stdlib.h> for C programs) if the compiler complains about the system function. Or you can use an instruction that reads something from the keyboard (e.g. cin.get();, getchar(); or cin>>variable;). In that case you may need to clear the input buffer before reading, e.g. cin.sync(); before cin.get();. Another option is to run your program from the command prompt; this is especially useful if you don't want it to wait before closing, or if it crashes before it reaches the keyboard-reading instruction.
    The birds and the bees.

  3. #3
    Registered User
    Join Date
    Jul 2006
    That's good. Well then, I really must've made no mistakes then, because I just followed the instructions in the Dev-C++ tutorial. Even though I can barely see it, I made a program. cool. I also saw the same exact thing in things I tried to enter on my laptop, so I guess the coder did the same thing.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having a bit of trouble with a binary search program
    By d-dub in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2006, 05:20 AM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM