两个结构体通过结构体指针传值

/*
	结构体之间通过指针传值 
*/

#include <stdio.h>
#include <string.h>

#define SALEN (sizeof(struct structA))
#define SBLEN (sizeof(struct structB))

typedef struct structA
{
	int a;
	char b[20];
	int c;
}*SA;

typedef struct structB
{
	char a[20];
	long b;
	char c;
}*SB;


/*
	将sb->a传给sa->b 
*/
int main(void)
{
	int temp=0;
	SA sa=(SA)malloc(SALEN);
	SB sb=(SB)malloc(SBLEN);
	system("color F4"); 
	printf("输入一串字符:");	
	scanf("%s",&(sb->a)); 
	printf("
输入字符串:【%s】",sb->a);
	printf("
开始转换,按1确认:");
	scanf("%d",&temp); 
	if(temp==1)
	{
		memcpy(&sa->b,&sb->a,sizeof(sb->a));
		printf("
从sb->a 到 sa->b");
		printf("
拷贝完成,结果是:【%s】

",sa->b);
	} 
}

 运行结果:

  

原文地址:https://www.cnblogs.com/achao123456/p/6305682.html