# mco_uda_field_alloc
RT

> Allocate vector elements.

### Prototype

        MCO_RET mco_uda_field_alloc(	/*IN*/ const mco_uda_object_handle_p obj,
                        /*IN*/ unsigned short field_no,
                        /*IN*/ unsigned short length );

### Arguments

obj | The object handle
field_no | The field number (must be between 0 and `struct_info.field_count` - 1)
length | The number of elements to allocate

### Description

Allocate a vector field.

### Return Codes

MCO_S_OK | Vector field successfully allocated
MCO_E_UDA_FIELD_NOT_FOUND | Invalid `fieldno` - field not found in this class or struct
MCO_E_UDA_NOT_DYNAMIC | The field referenced by `field_no` is not a vector

### Example

        Application snippet:

        int main(int argc, char* argv[])
        {
            MCO_RET rc;
            mco_uda_object_handle_t obj;
            mco_uda_value_t val;
            unsigned short field_no = 1;
            unsigned short vlength = 3;
            char buf[1024];

            ...

            /* Put a vector of chars */
            mco_uda_field_alloc(&obj, field_no, vLength); /* Allocate vector */

            val.type = MCO_DD_CHAR;  /* Set field's type */
            val.v.p.p.c = buf;       /* Set pointer to buffer */
            val.v.p.len = 20;        /* Set string length */
            for (j = 0; j < vLength; ++j)
            {
                sprintf(buf, "vch-%d:%d", 1, j); /* Put value to buffer */
                mco_uda_put(&rec, field_no, j, &val); /* Put value to object */
            }
            ...
        }

### Files

Header file:
mcouda.h
Source file:
mcouda.c
Library:
libmcouda.a