Hello world in C on BOSS (basic GCC usage)

So you are trying to set up BOSS for some C programming? Heres a basic how-to.

The first thing you’ll need is a compiler, gcc the GNU C Compiler comes installed by default in BOSS. Next you’ll need an editor, many editors(vi, nano, gedit to name a few) come installed by default in BOSS Linux. You can also use IDEs like Anjuta, Eclipse, Netbeans etc.

Lets get this started: we will be using Gedit, get to a terminal window(Applications>Accessories>Terminal) once on the terminal window type:

gedit firstfile.c

or any other filename of your choice in place of firstfile, be sure to use the .c extension. Otherwise GCC will not be able to recognize it as a C source file. Press the Enter key and type the following code in the Gedit window:

#include<stdio.h>

int main()

{

printf(“Hello World!”);

getchar();

return 0;

}

I am sure you have seen something like this before 🙂 its just a basic program to get you feet wet, Most students from India start off C/C++ programming with the Turbo C++ Version 3.0 compiler and are in the habit of using getch(); at the end of the code to basically make the execution wait for the user to press a key before completion. Well, conio.h is not a part of the C Language and it limited to old MS-DOS C Compilers, so I used getchar() in its place, it does pretty much the same thing in this program.

Now save the file and close gedit to get back to the terminal window. We will now compile firtsfile.c. Type:

gcc firstfile.c

If all goes well the prompt will reappear on the next line without any message, otherwise you’ll see an error message.

Now we will execute the file, the default name for the executable is a.out, to execute it type:

./a.out

and press Enter on the terminal, you will see:

Hello World

with the blinking cursor to the right of the d Press enter to return to the prompt.

On windows with Turbo C++ you have firstfile.exe as the executable generated, a.out is the default name for the executable file created by GCC. To use a name of your choice use the -o argument with gcc:

gcc firstfile.c -o firstfile

this will generate an executable by the name firstfile.

Happy Coding 🙂

Advertisements

One Response to Hello world in C on BOSS (basic GCC usage)

  1. […] I am sure you have seen something like this before its just a basic program to get you feet wet, Most students from India start of C/C++ programming with the Turbo C++ Version 3.0 compiler and are in the habit of using getch(); … read more […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: