cfunc.readnext C Function/C Functions


Command cfunc.readnext C Function/C Functions
Applicable release versions: AP 6.1
Category C Functions (120)
Description equivalent to the Pick/BASIC statement: readnext result,value from list

If expression is non-zero, then the "secondary" list is assumed.

The _CP_readnext call must be proceeded 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.

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.
Syntax int _CP_readnext(CPSTR** result, int* list, int* value, int expression)
The following example prints the first file name in the current account.

CPSTR * s = _CP_mkstr("select md with a1 "d]" sampling 
CPSTR * id = _CP_str_null;
int sl = -1;

_CP_execute(_CP_EXECUTE, s, (CPSTR**) 0, (CPSTR**) 0);
_CP_readnext(&id, &sl, (int*) 0, 0);

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)
Related cfunc.introduction