Hi,

I want a char array to point the memory location, which is pointed by a char pointer, without memcpy. I mean I do not need to copy all the elements again to another location

typedef struct
{
     long size;
     char data[1000];
}bulk;
 
bulk blob;

this doesn't work :

blob.data = (char *) ucBufrMessage;

it says;
error: incompatible types in assignment

Note : ucBufrMessage is an unsigned char pointer, pointing to a memory location which is full of assigned values.

Recommended Answers

All 3 Replies

So why not make the member of the struct to be unsigned char *data; Then you'll be able to perform the assignment without any casting.

The following changes will work
typedef struct
{
long size;
char * data[1000];
}bulk;

bulk blob;

blob.data[0] = &ucBufrMessage;

The following changes will work
typedef struct
{
long size;
char * data[1000];
}bulk;

bulk blob;

blob.data[0] = &ucBufrMessage;

That's not any different from this, except it wastes 999 pointers.

typedef struct
{
     long size;
     char *data;
}bulk;

bulk blob;

blob.data = &ucBufrMessage;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.