1、安装gccg++编译工具。
2、创建一个后缀名为.c的文件。
3、打开文件,准备编辑代码vimc.c.
4、编写一个简单的代码,包含头文件和main函数。
5、在终端窗口中输入gccc.c-otest编译代码。
6、输入./test命令回车即可。
以上就是小编的分享,希望能帮助的大家。
本文章基于ThinkpadE15品牌、centos7系统撰写的。
我不太明白你说的是什么意思,Linux下的C编程一般是通过gcc实现的。\x0d\x0a例如,创建了一个hello.c文本,在文本中写入\x0d\x0a#include\x0d\x0aintmain(void)\x0d\x0a{\x0d\x0aprintf(“helloworld!!”)\x0d\x0areturn0\x0d\x0a}\x0d\x0a然后在终端输入\x0d\x0a$gcc_ohellohello.c\x0d\x0a$/tmp/hello\x0d\x0a注:hello.c文件放在/tmp目录下,通过gcc-ohellohello.c命令生成一个hello文件,它是一个可执行文件,然后直接执行,就可以运行该程序了。姓名:冯成 学号:19020100164 学院:丁香二号书院
转自:https://feixiaoxing.blog.csdn.net/article/details/7229483
【嵌牛鼻子】linux C语言 管道通信
【嵌牛提问】linux下的C语言开发中的管道通信是什么?
Linux系统本身为进程间通信提供了很多的方式,比如说管道、共享内存、socket通信等。管道的使用十分简单,在创建了匿名管道之后,我们只需要从一个管道发送数据,再从另外一个管道接受数据即可。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int pipe_default[2]
int main()
{
pid_t pid
char buffer[32]
memset(buffer, 0, 32)
if(pipe(pipe_default) <0)
{
printf("Failed to create pipe!\n")
return 0
}
if(0 == (pid = fork()))
{
close(pipe_default[1])
sleep(5)
if(read(pipe_default[0], buffer, 32) >0)
{
printf("Receive data from server, %s!\n", buffer)
}
close(pipe_default[0])
}
else
{
close(pipe_default[0])
if(-1 != write(pipe_default[1], "hello", strlen("hello")))
{
printf("Send data to client, hello!\n")
}
close(pipe_default[1])
waitpid(pid, NULL, 0)
}
return 1
}
下面我们就可以开始编译运行了,老规矩分成两步骤进行:(1)输入gcc pipe.c -o pipe;(2)然后输入./pipe,过一会儿你就可以看到下面的打印了。
[test@localhost pipe]$ ./pipe
Send data to client, hello!
Receive data from server, hello!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)