# _CP_write

_CP_write is equivalent to the write or writeu BASIC statements.

The equivalency is dependent upon the *type* parameter.

| Type | BASIC Statement |
| --- | --- |
| _CP_WRITE | write string1 on expression,string2 |
| _CP_WRITEU | writeu string1 on expression,string2 |
The *expression* should be an integer
file descriptor returned by the _CP_open call.
This function returns -1 if an error occurs. The error code is contained
in _CP_errno.

## Syntax

```
int _CP_write(int type, CPSTR* string1, int expression, CPSTR* string2)
```

## Example(s)

```
/* Writes "hi" in item "myid" in "myfile". */

CPSTR * s = _CP_mkstr("myfile");
CPSTR * t = _CP_mkstr("hi");
CPSTR * id = _CP_mkstr("myid");
int f;

_CP_open(&f,_CP_str_null,s);
_CP_write(_CP_WRITE, t, f, id);
```

## See also

- [C functions overview](https://d3codex.com/cfunctions/c-functions-overview/)
- [_CP_close](https://d3codex.com/cfunctions/cp-close/)
- [_CP_open](https://d3codex.com/cfunctions/cp-open/)
- [_CP_read](https://d3codex.com/cfunctions/cp-read/)
- [_CP_writev](https://d3codex.com/cfunctions/cp-writev/)

---
Source: https://d3codex.com/cfunctions/cp-write/ - part of the D3Codex reference.
