running a c/c++ program in unix

This is not a question, but rather a simple how-to for
programmers who are new to the UNIX environment.

I too,am new to UNIX.
First I developed a few programs on my box and perfected them
until they were satisfactory for execution.

Problem was however, that once i compiled and all that,
it occured to me, that i was new to Unix and had no freakin
clue about how to run my apps from the command-line.

I couldn't for the life of me figure out how in the !$#@ to do this.

To experienced users, this is probably 'duh!' however, to a new
user like myself, this was all frustrating.

I spent a long time working on my little program and assumed that if it works it would run. Makes sense to me.
---------
Well, i was very wrong, and after i compiled my source file "myprogram.c" with the GNU CC compiler using the line:

cc myprogram.c

then another file appeared, called:

a.out

This was because i didn't specify a name for my program.

Having very little patients with the available documentation, I found nothing about running a program once you've created it.

So i tried typing my programs name in:

a.out [ENTER]

No good, instead i get a reply back saying:

a.out: Command not found.

I just wanted my freakin program to run.

Well, good news, it 'turns out' that prefixing the programs name with "./" works.

--thats a dot, a slash and then the programs path and name

so finally i entered:

./a.out [ENTER]

and voila! the darn thing worked.

If this seemed a bit long winded, it was.
I just hope this helps someone in the future.

late,
kray

You can get around with a solution over this. Try including the following line in your ~/.profile

export PATH=.:$PATH

That's because, when you try to execute a program, the shell looks only into the directories specified in the PATH environment variable. Since "." (the current directory) was not specified in the PATH, the shell never looked into your current directory. Hence, you had to specify the full relative path (./a.out), and it worked.

More better and easier way if you could add in -o option upon compiling.

gcc -o myprogram.c myprogram

and you could execute ./myprogram easily