# struct into a matrix

Page 1 of 1

## 1 Replies - 2170 Views - Last Post: 08 July 2009 - 07:57 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=113700&amp;s=78dc523e5bb9acfe9ed3f40f4345e6bb&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Beca

Reputation: 0
• Posts: 30
• Joined: 05-June 08

# struct into a matrix

Posted 08 July 2009 - 09:05 AM

Hello!

I'd like to know what can I do if I have a function like this:

"unsigned char function1( char* array)"

and then I need to use an "struct" as input parameter of "function1".
I can't change the source of the function and actually I shouldn't change the struct either, because it was define with typedef and it is used in many other programms.

The struct has 12 elements, some of them are also arrays like this:
unsigned char parameter1[8];
float parameter2[8];
int parameter2[2][2][2];

Best regards

Beca

Is This A Good Question/Topic? 0

## Replies To: struct into a matrix

### #2 gdismbit

Reputation: 0
• Posts: 1
• Joined: 08-July 09

## Re: struct into a matrix

Posted 08 July 2009 - 07:57 PM

Hi,

From what you've provided I take it that your function wants a pointer to an array of char's, so that's what you'll have to give it, i.e. you'll have to convert that data from the struct into that format. Copy data to a character array and assign the address of the array to a char pointer which you then use as the argument in the call to the function.

Obviously this has some issues, as not all the data within the struct are of the char data type. It would be helpful to now what the function actually does and if it actually requires all of the data within the struct. For instance, if only the data from the parameter1, the unsigned char array, is required you could assign the address of parameter1 to a char pointer variable and use that as your argument. i.e.

char* ptr1 = reinterpret_cast<char *> (&struct.parameter1);

function1(ptr1);

This would successfully deliver the character data from the parameter1 array into the function. Still as i mention, without knowing the actual usage of the function it's a little difficult to provide a better answer. Anyway, hope this is of use.