Noob question, command prompt
I'm fairly new to C and I've run into a problem that I can't seem to figure out. When I try to run a program, the command prompt window will flash really fast and close. How do I get the .exe to stay open?
I use Dev-C/C++,
Windows Service pack 2
2.8 ghz
516 ram
And it's not with just one program either, every source I try the command prompt window just flashes really fast.
Some sources I use:
Code:
#include <stdio.h>
main()
{
printf("hello, world\n");
}
and
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define TAX_RATE 0.05
main()
{
float balance;
float tax;
float total;
balance = 100;
tax = TAX_RATE * balance;
total = tax + balance;
printf("If you spend $%.1f, the tax will be $%.1f ... The total is $%.2f.", balance, tax, total);
}
How to Stop Compiler to See Output
This problem can be easily resolved if you use a function named getch(), which would force compiler to stop and you can view you output, but don't forget to put conio.h file in the header section and also conio.h is not valid in UNIX OS. The Code would be
Code:
//Header Files
#include<stdio.h>
#include<conio.h>
int main()
{
printf("Hello World");
getch();//Inbuilt Function Used
}