Problem compiling program

hi
i am having a problem that when ever i use
cc program_name.c
to compile a program. an error occurs, showing cc not found.
please help.

type this command:

which cc

If you get no output, your path does not point to the directory with cc in it. I'm inclined to think you may have gcc instead - also try:

which gcc

the output of commands was:

# which cc
no cc in /usr/sbin /usr/bin
# which gcc
no gcc in /usr/sbin /usr/bin
#

Check if you have the cc/gcc installed. If it is so, the PATH variable is not poiniting to the directory where the compiler is located. You have to give the full path of the cc/gcc and try compiling or set the PATH variable to the location where it is and it should work.

cc was installed but now i don't have any idea of its location. could u help me locating and adding that location into path. Or can you tell me any address from where i can get this package

cc/gcc is typically installed in /usr/bin. I am not sure about your system. If you want to find where the compiler could be located, run a find command.
find / -name "cc" -print
Replace 'cc' with 'gcc' if that is the compiler in your system.

i used the find command and found
/usr/ucb/cc
/cc
/cc/SUNWspro/bin/cc
/cc/SUNWspro/SC4.2/bin/cc
/cc/SUNWspro/SC4.2/include/cc

please help

Specify the full path of the cc to compile and see what you get. Once you are successful, add that cc path to the PATH variable in .profile.
/usr/ucb/cc cprog.c

sorry to say but i don't know how to make change in default path. Please could u help.

export PATH="/usr/ucb:$PATH"

if cc is in /usr/ucb
Put the above export statement in your .bashrc file (linux) or your .profile file. These are in your login directory. The next time you login it will take effect.

is there any way to check if cc in /usr/ucb is the required file, before i actually change the path.

which cc

will tell you what the path to cc is.

Edit:

I better make that clearer.
example: /usr/ucb/cc
the usr/ucb part is the path
example /usr/bin/opt/cc
the /usr/bin/opt/ part is the path

You will have to determine the path to cc yourself.

usr/ucb is not present in my default path. before making changes in the path i wish to check whether /usr/usb/cc actualy works or not.
will this command compile my program set.c
/usr/ucb/cc set.c

yes. -- assuming you have no errors in set.c.

It will create a compiled c file in the current directory named a.out

So you're on Solaris. Please forget about /usr/ucb/cc, it's a BSD compiler and doesn't have "high tech" ANSI features like, ... the const keyword. Try /cc/SUNWspro/bin/cc. If you're on Solaris 10, you should also have /usr/sfw/bin/gcc.

I get both a.out and hello2 when I compile hello2.c using gcc and cc.My problem is that when I want to run either a.out or hello2,I get the error:"bash: hello2: command not found"
I am in bash shell.
Thanks

yes, because the shell doesn't know where to find the executable and execute it. So, you just need to modify the above PATH environment variable.. add a . (which means current directory) add the beginning of your PATH env var:

export PATH=".:/usr/ucb:$PATH"

and rerun the .profile file (or .bashrc) with the command:

$ . .profile

now you should be able to execute your executable programs.. Before doing this you can try your exe by typing ./hello2 at command prompt and it should execute...

I added the export statement to .bashrc and .bash_profile and saved it
then I executed . .bashrc command from command prompt
then I compiled using cc -o hello2 hello2.c and gcc -o hello2 hello2.c
but I cannot run ./hello2

check if the binary that cc creates is executable

are u getting any cannot execute message ?
if so, change the perm bits of the executable

I changed the permission for the executable but I still get

bash: ./hello2: Permission denied
when I run hello2