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

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

问题描述

我想指定的char *字段为char *领域,但得到这个错误:

分配给当键入

不兼容的类型'的char [128]从类型'字符*'

我怎么能解决这个问题?为什么是这样?

  AddressItem_Callback_ContextType *上下文=(AddressItem_Callback_ContextType *)malloc的(的sizeof(AddressItem_Callback_ContextType));   //检查图标需要下载
   如果(pEntity->!cBigIcon [0] = 0){
      如果(res_get(RES_BITMAP,RES_SKIN,pEntity-> cBigIcon)== NULL){          上下文>图标= pEntity-> cBigIcon;
          上下文> IID = pEntity-> IID;         res_download(RES_DOWNLOAD_IMAGE,pEntity-> cBigIcon,NULL,,TRUE,1 addressItem_icon_download_callback,背景);
      }
   }

声明:

  typedef结构
{
    诠释IID; // POI类型ID
    INT iExternalPoiServiceID; //服务ID
    INT iExternalPoiProviderID; //提供商ID
    焦炭cBigIcon [MAX_ICON_LENGHT]
    焦炭cSmallIcon [MAX_ICON_LENGHT]
    焦炭cBigPromotionIcon [MAX_ICON_LENGHT]
    焦炭cSmallPromotionIcon [MAX_ICON_LENGHT]
    焦炭cOnClickUrl [MAX_URL_LENGTH]
..
} RTExternalPoiType;typedef结构
{
    诠释IID; // POI类型ID
   // INT iExternalPoiServiceID; //服务ID
   // INT iExternalPoiProviderID; //提供商ID
    焦图标[MAX_ICON_LENGHT]
} AddressItem_Callback_ContextType;


解决方案

数组名是不能修改这些常量指针。在这种情况下图标是一个常量指针以及

 上下文>图标= pEntity-> cBigIcon;

在这里你要修改它,这是不允许的。

试试这个..

的strcpy(上下文>图标,pEntity-> cBigIcon);

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

incompatible types when assigning to type 'char[128]' from type 'char *'

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 );
      }
   }

declarations:

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;

解决方案

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.

Try this ..

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

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

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