tags:

views:

65

answers:

2

Hi guys. I'm a total beginner in C programming so please bear with me. I have just started today and wanted to write a short program - well at least a small script that would just print out a line of text. Now here's what I did in order to achieve this:

I downloaded vim text editor and wrote this few lines of code:

#include <stdio.h>
int main(void)
{
    printf("This is some text written in C \n");
    return 0;
}

I saved it as inform.c and compiled it using "cc inform.c" command.

In the end I got a.out file but when I'm trying to run it says:

-bash: a.out: command not found

Can someone tell what I'm doing wrong here and point me in the right direction? Thanks.

+4  A: 

Bash can't find your command because the current directory is not usually in the path.

Try:

$ ./a.out
Seth
Thanks. That helped.
Pavel
A: 

It's a basic one.

on Mac, you need to specify were your executable is. when you type a.out, the system look for the command in /usr/bin and other synstem binaries folders.

to be more precise type ./a.out

which basically says : "in this directory, command a.out"

you should also add directly the classical signature of main which is : int main(int argc, char ** argv);

dzada
Also `int main(void)` is correct according to the standard.
Matteo Italia
`int main()` or `int(void)` works too, and is better than the two-arg version if you have no intention of using command-line arguments.
cHao