管道、指针的联合使用

#include <stdio.h>
#include<unistd.h>

int main(int argc, const char* argv[])
{
	int Ret;
	
	char buf[] = "123123123123121231232122321312";
	char * pread = NULL;
	char * pwrite = buf;
	
	int pipetest[2];
  	if(pipe(pipetest) < 0)
  	{
		printf(" face lib to vo pipe creat error!");
  	}
	else
	{
		printf(" face lib to vo pipe creat success!\n");
	}
	
	printf("%s \n", buf);
	
	/* 管道 发送/接收 指针必须是  &指针  的格式 */
	/* 接收的正常使用指针即可 */
	Ret = write(pipetest[1], &pwrite, sizeof(pwrite));
	if(Ret >= 0)
	{
		printf("%s sizeof(pwrite) %lu\n",  pwrite, sizeof(pwrite));
	}

	Ret = read (pipetest[0], &pread, sizeof(pread));
	if(Ret >= 0)
	{
		printf("%s sizeof(pread) %lu\n",  pread, sizeof(pread));
	}
	
	close(pipetest[0]);
	close(pipetest[1]);
}

另外:
A* -> void* -> int -> A*
A* tmp类型通过传参 转化为 void* tmp, 然后转化成int a, 然后赋值转化成A* aa = a;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值