malloc动态申请'内嵌'结构体的内存

 

在做怦怦交易的客户端碰到的结构体问题



typedef enum ITEMTYPE
{
    NoneItem = 0,//空类型的Item
    LeftItem = 1,//聊天公告我的
    TopItem = 2,//专栏本子资源
    CenterItem = 3 //中间的显示消息
} ItemType;


typedef enum INDEX
{
    Index_LiaoTianItem = 0,
    Index_GongGaoItem = 1,
    Index_WoDeItem = 3,
    Index_ZhuangLangItem = 4,
    Index_BenZiItem = 5,
    Index_ZiYuangItem = 6,
    Index_DisplayItem = 7,
    Index_DisplayItem1 = 8,
    Index_DisplayItem2 = 9,
    Index_DisplayItem3 = 10,
    Index_DisplayItem4 = 11,
    Index_DisplayItem5 = 12


}Index;


typedef struct TEXT_STRUCT
{
    char * text; //项目中的文字
    int x,y; // item中文字的位置
    int width,height; //项目区域中文字占的大小
} Text_Struct;


typedef struct IMAGE_STRUCT
{
    char * imagePath; // item中图片的路径
    int x,y; // item中图片的位置
    int width,height; //项目中图片的宽高
} Image_Struct;


//定义传入实例item的参数结构体
typedef struct ITEMARGUMENT
{
    Index index; // item的索引
    ItemType type; // item的类型
    int x,y; // item的坐标
    int width,height; // item的大小
// char * PicturePath; //图片的路径
// char *文本; // CenterItem显示的文字
    Text_Struct * Text;
    Image_Struct *图像;

} ItemArguments;


我是这样申请的,感觉不专业,嗯。凑全着用

    ItemArguments * MyItemArguments = NULL ; 
    Text_Struct * aa =(Text_Struct *) malloc sizeof Text_Struct ));  
    Image_Struct * bb =(Image_Struct *) malloc sizeof Image_Struct ));  
    MyItemArguments =(ItemArguments *) malloc sizeof ItemArguments )); 
    MyItemArguments - > Text = aa ;
    MyItemArguments - > Image = bb ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值