_CP_readnext

_CP_readnext is equivalent to the readnext result,value from list BASIC statement.

Syntax

int _CP_readnext(CPSTR** result, int* list, int* value, int expression)

If expression is nonzero, then the secondary list is assumed. The _CP_readnext call must be preceded by a _CP_select call or a _CP_execute call which produces an external select list. In the case of an external list generated by a _CP_execute, the user should pass a pointer to an int containing -1 as the list parameter when readnext is first called.

Description

This function returns -1 if an error occurs. The error code is contained in _CP_errno. This situation occurs when there are no more items in the list. In this case, _CP_errno will contain PE_END_LIST.

TIP

When possible, the user should use _CP_select on a file rather than a _CP_execute of a TCL select command as the _CP_select call is much more efficient.

Example(s)

/* Prints the first file name in the current account. */

 

CPSTR * s = _CP_mkstr("select md with a1 \"d]\" sampling 1");

CPSTR * id = _CP_str_null;

int sl = -1;

 

_CP_execute(_CP_EXECUTE, s, (CPSTR**) 0, (CPSTR**) 0);

_CP_readnext(&id, &sl, (int*) 0, 0);

_CP_print(id);

 

/* The following example prints the item names in "myfile". */

 

CPSTR * n = _CP_mkstr("myfile");

CPSTR * id = _CP_str_null;

int sl = -1;

int f = -1;

 

_CP_open(&f, _CP_str_null, n);

_CP_select(f, &sl, 0);

while (_CP_readnext(&id, &sl, (int*) 0, 0) >= 0)

_CP_print(id);

See Also

C Functions Overview