简体   繁体   中英

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.

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

Try:

$ ./a.out

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM