Monday 25 March 2013

C Program to Check the Arrow Key Pressed

#include<stdio.h>
#include<conio.h>

void main()
{
     char c;
     clrscr();
     fflush(stdin);//To clear the keyboard buffer of all characters
     c=getch();
     printf("%d",c);
     if(c==0)
     {
            c=getch();
            if(c==0x48u)
                   printf("Up Arrow = %02X",c);
            else if(c==0x50u)
                   printf("Down Arrow = %x",c);
            else if(c==0x4bu)
                   printf("Left Arrow = %x",c);
            else if(c==0x4du)
                   printf("Right Arrow = %x",c);
    }
  }

Wednesday 19 December 2012

Eclipse Juno IDE for C/C++ Simplified for Windows Machine

Installation

If this the first time you are using Eclipse, try the following steps to install and run it successfully.

1. Download from http://www.eclipse.org/downloads/

Eclipse IDE for C/C++ Developers

Check if your machine is of 32 or 64 bit using the link below if you are working in windows.

http://support.microsoft.com/kb/827218#method1


2. The C/C++ compiler also needs to be installed.

Download MinGW from

http://sourceforge.net/projects/mingw/files/MinGW/

By default Eclipse searches for MinGW in C:\, so ensure that there is a folder C:\MinGW


Opening Eclipse

1. Inside the Eclipse folder, click the "eclipse" application to launch eclipse

2. This will prompt you to select a workspace.

Give the path in which you would like your programs to be saved.



Creating the first C program

For college students migrating from Turbo C, the concpet of projects will be new. All programs are written in files inside projects.

So first we will create projects and then add files to it.

1. Creating a Project

File --> New --> C Project

Give a Project Name :
Eg. First

In Project Type :
Choose Executable --> Empty Project

In Toolchains:
Choose MinGW GCC

Click Next

In Select configurations
Check both Debug and Release

Click Finish

The project is listed in the project explorer in the left corner or take it from

Window --> Show View --> Project Explorer

2. Creating files inside project

Right click the Project Name.
i.e. First in our example.

Click New --> Source File

A "New Source File" window opens.
Give the name of the C file in Source File.
Eg. Source File : Main.c (c in lower case)

In the Editor panel for Main.c the program can now be typed.

Type a simple program.

Example

#include<stdio.h>

int main()
{
  printf("Hi");
  return 0;
}

"Unresolved Inclusion" Error

If you get the "Unresolved Inclusion error next to the #include, it means that the path has not been set properly.

Right Click the Project. i.e. First
  • Open the Properties Window
  • Expand C/C++ General
  • Click Paths and Symbols
  • In Includes tab
  • Click GNU C in Languages
  • Click Add thrice and add the following paths (assuming mingw is in C:\)
    • c:/mingw/lib/gcc/mingw32/4.6.2/include
    • c:/mingw/include
    • c:/mingw/lib/gcc/mingw32/4.6.2/include-fixed

3. Build Project

Right click the project or use the "Project" menu.
Select "Build Project"

4. Run

Right Click the project and click
Run As --> Local C/C++ application

or

Click the run symbol (like the play button)