从类型“char *"分配给类型“char[128]"时的类型不兼容 [英] incompatible types when assigning to type 'char[128]' from type 'char *'

查看:22
本文介绍了从类型“char *"分配给类型“char[128]"时的类型不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 char* 字段分配给 char* 字段,但出现此错误:

I'm trying to assign char* field to char* field, but get this error:

从类型 'char *' 分配给类型 'char[128]' 时的类型不兼容

我该如何解决这个问题?为什么会这样?

how can I fix this? and why is that happening?

    AddressItem_Callback_ContextType *context = (AddressItem_Callback_ContextType *)malloc(sizeof(AddressItem_Callback_ContextType));

   //check if icons need to be downloaded
   if (pEntity->cBigIcon[0] != 0){
      if (res_get(RES_BITMAP,RES_SKIN, pEntity->cBigIcon) == NULL){

          context->Icon = pEntity->cBigIcon;
          context->iID = pEntity->iID;

         res_download(RES_DOWNLOAD_IMAGE, pEntity->cBigIcon, NULL, "",TRUE, 1, addressItem_icon_download_callback, context );
      }
   }

声明:

typedef struct
{
    int  iID;        //  POI Type ID
    int  iExternalPoiServiceID; // Service ID
    int  iExternalPoiProviderID; // Provider ID
    char cBigIcon[MAX_ICON_LENGHT];
    char cSmallIcon[MAX_ICON_LENGHT];
    char cBigPromotionIcon[MAX_ICON_LENGHT];
    char cSmallPromotionIcon[MAX_ICON_LENGHT];
    char cOnClickUrl[MAX_URL_LENGTH];
..
} RTExternalPoiType;

typedef struct
{
    int  iID;        //  POI Type ID
   //int  iExternalPoiServiceID; // Service ID
   // int  iExternalPoiProviderID; // Provider ID
    char Icon[MAX_ICON_LENGHT];
} AddressItem_Callback_ContextType;

推荐答案

数组名是不能修改的常量指针.在这种情况下 Icon 是一个常量指针和

Array names are constant pointers you can not modify them. In this scenario Icon is a constant pointer and

            context->Icon = pEntity->cBigIcon;

在这里你试图修改它,这是不允许的.

here you are trying to modify it, which is not allowed.

试试这个..

strcpy(context->Icon,pEntity->cBigIcon);

strcpy(context->Icon,pEntity->cBigIcon);

这篇关于从类型“char *"分配给类型“char[128]"时的类型不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆