home *** CD-ROM | disk | FTP | other *** search
- /*********
- * Atnext.c by Leonard Zerman
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: ATNEXT( <expC>, <expC>, <expN> )
- * Return: The position of <n> occurance of char in string.
- * Note : Returns 0 if not found.
- ********/
-
- #include "trlib.h"
-
- TRTYPE atnext() /* declare the atnext function */
- {
- char *instr; /* a pointer to the passed string */
- char *c; /* a pointer to the char to be found */
- int i, n, po_found; /* the position of the find */
-
- if (PCOUNT == 3 && ISCHAR(1) && ISCHAR(2) && ISNUM(3))
- {
- c = _parc(1) ;
- instr = _parc(2) ; /* assign the address to instr */
- n = _parni(3);
- }
- else
- {
- _retni(ERRORNEG); /* return a syntax error */
- return; /* return from program */
- }
- if ( n == 0 ) /* return because of invalid parameter */
- _retni(0);
-
- po_found = 0;
- for (i = 0; instr[i] ; i++ ) /* while not at end of string */
- { /* and the count of n != 0 */
- if (instr[i] == *c ) /* if a char match */
- {
- if (!(--n)) /* If this is the occurence we want */
- {
- po_found = ++i; /* return the position */
- break;
- }
- }
-
- }
- _retni(po_found);
- return;
- }
-
-