---
name: "mtext_from_data"
section: "3m17n"
platform: "linux"
package: "m17n-docs"
version: "1.8.4-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mtext_from_data"
---

# mtext\_from\_data(3m17n)

## NAME

mtext\_from\_data -

## SYNOPSIS

**MText**\* **mtext\_from\_data** (const void \* *data*, int *nitems*, enum **MTextFormat** *format*)

## DESCRIPTION

Allocate a new M-text with specified data. The **mtext\_from\_data()** function allocates a new M-text whose character sequence is specified by array **data** of **nitems** elements. **format** specifies the format of **data**.

When **format** is either **MTEXT\_FORMAT\_US\_ASCII** or **MTEXT\_FORMAT\_UTF\_8**, the contents of **data** must be of the type `unsigned` `char`, and **nitems** counts by byte.

When **format** is either **MTEXT\_FORMAT\_UTF\_16LE** or **MTEXT\_FORMAT\_UTF\_16BE**, the contents of **data** must be of the type `unsigned` `short`, and **nitems** counts by unsigned short.

When **format** is either **MTEXT\_FORMAT\_UTF\_32LE** or **MTEXT\_FORMAT\_UTF\_32BE**, the contents of **data** must be of the type `unsigned`, and **nitems** counts by unsigned.

The character sequence of the M-text is not modifiable. \
\
  The contents of **data** must not be modified while the M-text is alive.

The allocated M-text will not be freed unless the user explicitly does so with the **m17n\_object\_unref()** function. Even in that case, **data** is not freed.

## RETURN VALUE

If the operation was successful, **mtext\_from\_data()** returns a pointer to the allocated M-text. Otherwise it returns `NULL` and assigns an error code to the external variable **merror\_code**. \

## ERRORS

`MERROR_MTEXT`\

## COPYRIGHT

Copyright (C) 2001 Information-technology Promotion Agency (IPA)\
 Copyright (C) 2001-2011 National Institute of Advanced Industrial Science and Technology (AIST)\
 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License  \<http://www.gnu.org/licenses/fdl.html\>.
