Let’s say you have this structure:
struct MMFS_IDENTIFICATION
{
char *szVendor;
char *szControllerModel;
char *szRevision;
char *szId;
char *szExecutive;
char *szKarelRevision;
char *szProcessName;
char *szCommRevision;
char *szRobotModel;
};
Is there any easy way to do something like this?
MMFS_IDENTIFICATION mmfsId;
for( int i = 0; i < 9; i++ )
{
int len = buf[pos++];
mmfsId[i] = malloc(len);
memcpy( mmfsId[i], buf[pos], len );
pos += len;
}
The only thing I know to do is copy and paste the code nine times. But I really don’t want to do that because in the real program I’m using this concept for, calculating len is not as simple as I made it in this example.
Since all of the structure members are
char*pointers, you could do something like this: