Computing.Net > Forums > Programming > beginners programming in c

beginners programming in c

Reply to Message Icon

Original Message
Name: y2jtalukder
Date: August 13, 2004 at 17:27:46 Pacific
Subject: beginners programming in c
OS: Win 98se
CPU/Ram: N/A
Comment:

Hi,
I have decided to learn how to program in c, eventually to move onto c++ as I can see its the way to go for windows programming. To start the right way I went and got "The C programming language" by Kernighan and Ritchie. The amusing thing is although I programmed a lot in java before, Im stuck on the first program. Here is the familiar hello world program from 1st chapter:

#include <stdio.h>

main()
{
printf("hello, world\n");
}

The problem is when I compile and run it, the dos window only shows very quickly and then disappears, and so I cant see if the code has worked or not. Can anyone help me out? Also could you explain any changes. And by the way Im using Borland C++ builder 6. Thanks in advance.


Report Offensive Message For Removal


Response Number 1
Name: Don Arnett
Date: August 13, 2004 at 18:13:18 Pacific
Subject: beginners programming in c
Reply: (edit)

Two things are combining to do this to you.

First, the only thing the program does is output one line then quit.

Second, the program is being invoked in a dos shell is such a way that the dos shell quits when the program is done.

You need to change one of these factors.

One option is to open a dos shell, CD to the directory where your executable is, then execute it. Then you'll see the output because the dos shell won't close when the program is done.

The second (and more used) option is to put some type of input statement at the end of the program. This will cause the program to stop and wait for input, allowing you to see the screen contents.

Add the line:

getchar();

into your code before the last }

This will cause the program to stop until you press a key (on some compilers you may have to press ENTER)


Report Offensive Follow Up For Removal

Response Number 2
Name: BlueRaja
Date: August 13, 2004 at 20:50:32 Pacific
Subject: beginners programming in c
Reply: (edit)

You should provide a return type for main(), even it's simply "void". Also, include a "return" statement.


Report Offensive Follow Up For Removal

Response Number 3
Name: Clicker
Date: August 14, 2004 at 02:04:45 Pacific
Subject: beginners programming in c
Reply: (edit)

this should get it working...

#include <stdio.h>

int main()
{
printf("Hello, World!\n");
return 0;
}


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: beginners programming in c

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge