Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

simple C program help

Status
Not open for further replies.

aersoy

Member level 3
Member level 3
Joined
Aug 8, 2006
Messages
60
Helped
2
Reputation
4
Reaction score
1
Trophy points
8
Location
ankara turkey
Activity points
0
i have just started C programming actually 5 minutes ago

i use DEV C++ version 4.9.9.2

and my operating system is WinXP home edition SP2

i have created simple program as in the book but i cannot open the exe file

using the below source code

</pre>
#include<stdio.h>
/*function main begins program execution*/
int main ()
{
printf ("Welcome to C!\n");

return 0;
}
</pre>

but the exe file closes as soons as i open it

what should i do to solve this program?

thanx :D
 

You should execute the exe file in command line.
Not double click the exe file for executing. Then you will see the message"Welcome to C!"
 

    aersoy

    Points: 2
    Helpful Answer Positive Rating
Your EXE is a "Windows console application". If you launch it from Windows Explorer, Windows opens a command prompt window, runs your program until it exits, and then closes the command prompt window. That all happens super-fast, so you probably won't see your message.

As RDRyan suggests, you can manually open a Command Prompt window, and then run your program from the command line.
 

    aersoy

    Points: 2
    Helpful Answer Positive Rating
insert :
#include "conio.h"
and getch(); after return 0;
 

    aersoy

    Points: 2
    Helpful Answer Positive Rating
Oh no , i still use it , if you use C++ syntax in dev C++ use must insert : using namespace std ; before main () :D
 

You ay also try the following :
#include <conio.h>

then at the end of your program, write :

while(!kbhit());//this would pause the program till any key is pressed .
 

    aersoy

    Points: 2
    Helpful Answer Positive Rating
The best solution to this problem is to include:
system( "pause" );
as the last line of your code & immediately before return 0;
This will keep the DOS window open until you press a key.
This is documented in the Dev C++ help files.
 

    aersoy

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top