Installing and using Dev-C++

From Wikiversity
Jump to navigation Jump to search

This little article will teach you how to install the latest version of Dev-C++ and how to write a C program in it. This way, you will know how to write C programs, compile, and find the executable.

Dev-C++ is not actually a compiler, but an IDE. The link below is an installation of Dev-C++ which is prepackaged with MinGW. MinGW is the GCC compiler but made for usability in Windows.

Downloading[edit | edit source]

Click on this

Thumb
Thumb

Installing[edit | edit source]

Hit all the next buttons.

Using Dev-C++[edit | edit source]

By default Dev-C++ is installed to C:\Dev-Cpp.

Go there and open up the .exe called devcpp.

It should look something like this.

Thumb
Thumb

Creating a Project[edit | edit source]

To write a program, you have to make the source code files. To do this you create a project.

To create a project you go to File > New > Project.

Thumb
Thumb

A dialog will come up asking you what kind of project you would like to make, what you would like to name it, and if you want to compile in C++ or C. There are many project templates for different types of programs. Select the Console Application template and the language you want to compile in is C. Then name the project something. It would be recommended that when you save this project, that you should save it to it's own folder. You should probably make a folder under C:\Dev-Cpp called Projects and then make a folder this project. The reason being wherever you save this project it'll create multiple files and could get cluttered very fast if you do not make a folder.

Thumb
Thumb

Compiling and Executing[edit | edit source]

Compiling and executing a program is very simple. You can hit F9 to compile and execute or click the button.

Thumb
Thumb

If all goes well then a console should come up and display "Press any key to continue..."

The Interface[edit | edit source]

There are many features, and the Dev-C++ is pretty easy to understand. There are two important windows that you should know to get you started.

The first is where you actually edit the source code for your programs. It has syntax highlighting and formatting making it easier to read.

Thumb
Thumb

The second would be the navigating of your projects and your source code files. This is so you can see how your projects are organized.

Thumb
Thumb
/*
PROJECT : BIRTHDAY CALCULATOR
PROGRAMMER : MD. SALAH UDDIN
EMAIL : salahuddinlovelu@gmail.com
*/

#include <stdio.h>
#include <time.h>

/* checks whether the given input is leap year feb or not */
int lYear(int year, int mon) {
int flag = 0;
if (year % 100 == 0) {
if (year % 400 == 0) {
if (mon == 2) {
flag = 1;
}
}
} else if (year % 4 == 0) {
if (mon == 2) {
flag = 1;
}
}
return (flag);
}

int main() {
/* days in months */
int dInM[] = {31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31};
int days, month, year;
char dob[100];
time_t ts;
struct tm *ct;

/* get the date of birth from the user */
printf("Enter your days of birth [day/month/year]: ");
fgets(dob, 100, stdin);
sscanf(dob, "%d/%d/%d", &days, &month, &year);
ts = time(NULL);
ct = localtime(&ts);
/* scan the year, month and year from the input string */
printf("\nCurrent Date: %d/%d/%d\n",
ct->tm_mday, ct->tm_mon + 1, ct->tm_year + 1900);

days = dInM[month - 1] - days + 1;

/* checking whether month is leap year feb - 29 days*/
if (lYear(year, month)) {
days = days + 1;
}

/* calculating the no of days, years and months */
days = days + ct->tm_mday;
month = (12 - month) + (ct->tm_mon);
year = (ct->tm_year + 1900) - year - 1;

/* checking for leap year feb - 29 days */
if (lYear((ct->tm_year + 1900), (ct->tm_mon + 1))) {
if (days >= (dInM[ct->tm_mon] + 1)) {
days = days - (dInM[ct->tm_mon] + 1);
month = month + 1;
}
} else if (days >= dInM[ct->tm_mon]) {
days = days - (dInM[ct->tm_mon]);
month = month + 1;
}

if (month >= 12) {
year = year + 1;
month = month - 12;
}

/* print the result */
printf("\nYour age: %d year %d months and %d days\n\n",year, month, days);
printf("THANKS FOR USE THIS SOFT\n\n MD.SALAH UDDIN LOVELU\n\n LECTURER KURERPAR ADARSHA COLLEGE\n\n MURADNAGOR, COMILLA.");
return 0;
}

See also[edit | edit source]