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.?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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