Pavel
Pavel

Reputation: 5353

Problem with running c program on mac?

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.

Upvotes: 1

Views: 279

Answers (2)

dzada
dzada

Reputation: 5874

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);

Upvotes: 0

Seth
Seth

Reputation: 46443

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

Try:

$ ./a.out

Upvotes: 4

Related Questions