返回结构指针的函数怎么写啊??? 我定义了一个结构包括三个元素,char *a,char *b,char *c;我需要写的函数是对其中的元素进行判断。如果符合条件就复制一份,然后返回新的结构指针。这个函数怎么写啊? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 typedef struct {char *a; char *b; char *c;} my_struct;my_struct* my_function (const my_struct *param){ if (....) { my_struct *temp = (my_struct *)malloc(sizeof(my_struct)); if (!temp) return NULL; // TODO: copy the struct return temp; } else { return NULL; }} 怎么写都行吧。typedef struct tagTFRAME{ IP tag; char type; char cparam; short len; char data;}TFRAME;typedef union tagFRAME{ TFRAME frame; char bytes[ sizeof( TFRAME ) ];}FRAME;FRAME CLakerDlg::GetFrame(char * buf){ FRAME temp_frame; memcpy( temp_frame.bytes, ( const void * )( buf + 12 ), sizeof( FRAME ) ); temp_frame.frame.tag.longs = ( int )ntohl( temp_frame.frame.tag.longs ); temp_frame.frame.len = ntohs( temp_frame.frame.len ); return temp_frame;}上边的是返回结构体的楼上的是返回结构体指针的typedef可以不用 怎样把utf-8转换成gb格式的编码,要c++控制台的代码,谢谢 再问,怎么将属性页和static关联起来 大家给一个思路,关于设置Openl开关的?vc++的 Windows NT和XP的区别是什么? 批量文件重命名问题.... 如何获取CRichEditCtrl中没一行的文本????????????????????????????????? 文本处理问题 关于内存和文件存取讨论:欢迎大侠讨论 200分送上 急需smime相关 祝jennyvenus新年快乐... vc toolbar 有没有CGridList的类啊??怎么设置一个表格List啊??
{
if (....) {
my_struct *temp = (my_struct *)malloc(sizeof(my_struct));
if (!temp) return NULL;
// TODO: copy the struct
return temp;
} else {
return NULL;
}
}
typedef struct tagTFRAME
{
IP tag;
char type;
char cparam;
short len;
char data;
}TFRAME;
typedef union tagFRAME
{
TFRAME frame;
char bytes[ sizeof( TFRAME ) ];
}FRAME;FRAME CLakerDlg::GetFrame(char * buf)
{
FRAME temp_frame;
memcpy( temp_frame.bytes, ( const void * )( buf + 12 ), sizeof( FRAME ) );
temp_frame.frame.tag.longs = ( int )ntohl( temp_frame.frame.tag.longs );
temp_frame.frame.len = ntohs( temp_frame.frame.len ); return temp_frame;
}上边的是返回结构体的
楼上的是返回结构体指针的
typedef可以不用