Problem with using strncpy() and memcpy()

Hi!

I'm having a problem with using the functions strncpy and memcpy().

I'm writing a function to initialise a structure. It gets two arrays passed by array. I need to write the contents of these to the corresponding fields of the structure, which are arrays of exactly the same type and size. I didn't want to write out this assignment by hand, so I tried to use the functions strncpy() and memcpy() for this goal. But for some reason my compiler ( G++ on Ubuntu Linux 10.04 ) refuses to compile this function and gives me errors related to the calls to these functions.

Here is the code for the function:

1
2
3
4
5
6
7
8
9
10
void init_airline_reservation( airline_reservation& the_airline_reservation, 
                               unsigned int field_one, 
                               char field_two[2][4], 
                               unsigned int field_three[2][2] ) {
    the_airline_reservation.flight_number = field_one;
    strncpy( the_airline_reservation.airports[0][0], field_two[0][0], 3 );
    strncpy( the_airline_reservation.airports[1][0], field_two[1][0], 3 );
    memcpy( the_airline_reservation.times[0][0], field_three[0][0], 2 );
    memcpy( the_airline_reservation.times[1][0], field_three[1][0], 2 );
}


I'm still a beginner, so I have no clue what's going wrong.

Thank you in advance for your help.
Both strcpy and memcpy need source and destination addresses. field_two[0][0] and the others, however is a value. Use &field_two[0][0] or field_two[0].
Topic archived. No new replies allowed.