在Linux系统中,如何运行一个C语言程序?

在Linux系统中,如何运行一个C语言程序?,第1张

我不太明白你说的是什么意思,Linux下的C编程一般是通过gcc实现的。

例如,创建了一个hello.c文本,在文本中写入

#include <stdio.h>

int main(void)

{

printf(“hello world!!”)

return 0

}

然后在终端输入

$ gcc –o hello hello.c

$ /tmp/hello

注:hello.c文件放在/tmp目录下,通过gcc -o hello hello.c命令生成一个hello文件,它是一个可执行文件,然后直接执行,就可以运行该程序了。

#include <stdio.h>

#include <unistd.h>

int main (int argc, char **argv)

{

int oc/*选项字符 */

char *b_opt_arg /*选项参数字串 */

while((oc = getopt(argc, argv, "n:")) != -1)

{

switch(oc)

{

case 'n':

b_opt_arg = optarg

break

}

}

printf("hello world : %s\n",b_opt_arg)

return 0

}

运行结果:

# ./hello -n 3

hello world : 3


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8451281.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-16
下一篇 2023-04-16

发表评论

登录后才能评论

评论列表(0条)

保存