MATLAB Application Program Interface
  Go to function:
    Search    Help Desk 
mxGetString    Examples   See Also

Copy a string mxArray's data into a C-style string

C Syntax

Arguments

array_ptr
  Pointer to a string mxArray; that is, a pointer to an mxArray having the mxCHAR_CLASS class.

buf
  The starting location into which the string should be written. mxGetString writes the character data into buf and then terminates the string with a NULL character (in the manner of C strings). buf can either point to dynamic or static memory.

buflen
  Maximum number of characters to read into buf. Typically, you set buflen to 1 plus the number of elements in the string mxArray to which array_ptr points. (See the mxGetM and mxGetN reference pages to find out how to get the number of elements.)

Note: Users of multibyte character sets should be aware that MATLAB packs multibyte characters into an mxChar (16-bit unsigned integer). When allocating space for the return string, to avoid possible truncation you should set

Returns

0 on success, and 1 on failure. Possible reasons for failure include

Description

Call mxGetString to copy the character data of a string mxArray into a C-style string. The copied C-style string starts at buf and contains no more than buflen-1 characters. The C-style string is always terminated with a NULL character.

If the string array contains several rows, they are copied, one column at a time, into one long string array.

Examples

Use mxGetString to convert the data from a string array into a C string named buf:

For an additional example, see mxgetstring.c in the mx subdirectory of the examples directory.

See Also

mxCreateCharArray, mxCreateCharMatrixFromStrings, mxCreateString



[ Previous | Help Desk | Next ]