Where to put the file and how to compile and run i

2019-09-21 16:36发布

I want to learn how to write a C program under Linux. Now I have installed Centos, and I'm using vim to write a 'hello world' program in the C language. But I don't know where to put it, or how to compile it? I have installed gcc. I am sorry. I am a newbie. Thank you. Could you make me an example how to write a simple program in C then test and compile it.?

标签: c linux
2条回答
时光不老,我们不散
2楼-- · 2019-09-21 17:14

type this in your terminal:

$ mkdir ~/learnC
$ cd ~/learnC
$ cat > hello.c 

   #include <stdio.h> 
   int main () { 
      printf("Hello World\n"); 
   } 

/* Press Ctrl+D */

$ gcc hello.c -o hello
$ ./hello
查看更多
Anthone
3楼-- · 2019-09-21 17:35

Save it anywhere, then in a terminal run

gcc path/to/file.c

That's all it takes. The default output will be a file called a.out which you can run directly from the terminal.

If you're uncomfortable with the terminal (though since you're using vim I'll assume you're not), there are many IDEs that make it even easier for beginners.

查看更多
登录 后发表回答