tags:

views:

101

answers:

5

Hi I have the following program. When I compile on the terminal gcc main.c I do get an executable named a.out. However if I type a.out in the terminal I get the following message: a.out: command not found

Any ideas on what I might be doing wrong?

#include <stdio.h>
#include <stdlib.h>

#define PROMPT "print something"
/*
 * 
 */
int main() {

    printf("CS-xxx Assignment x, xxxxx\n");

    printf(PROMPT);

    return (EXIT_SUCCESS);

}
+10  A: 

Assuming you use a Unix-based system, usually "." is not in the path: So, try ./a.out

E Dominique
+1 beat me to it
Andy White
thanks... that fixed it.
+1  A: 

You might not have "." (current directory) in your PATH environment variable.

Try running "./a.out" or add "." to your PATH.

Andy White
But bear in mind that "." is not in the $PATH for security reasons, so unless you really need to - avoid to add it to your $PATH.
E Dominique
I'm with E Eominique: don't do it. But if you *must*, always put '.' it at the *end* of the search path.
dmckee
+4  A: 

Try using

./a.out

Most Linux systems will not look in the current directory for executables, so you need to tell it to look in the current directory.

crashmstr
+1  A: 

Use

./a.out

You must run program specifying current directory.

Burgos
A: 

Just type ./a.out and things should work. The issue is without ./ the shell thinks you are typing in a command.

Missoula
He *is* typing in a command. The shell just doesn't find one of that name on `$PATH`.
dmckee