NXTARG
Section: C Library Functions (3)
Updated: 5/31/86
Index
Return to Main Contents
NAME
nxtarg - parse arguments from a string
SYNOPSIS
extern char _argbreak;
char *nxtarg (p,brk);
char **p,*brk;
DESCRIPTION
Nxtarg
is used to parse a string, picking off one argument
with each call of
nxtarg.
The arguments are separated by some special "break"
characters, and may additionally be surrounded by
leading and trailing blanks and tabs.
When you have a string which you wish to parse, you should
declare a pointer and point to the start of the string:
-
char string[100]; /* the arg list */
char *pointer; /* a pointer */
char *argument; /* one argument */
pointer = string; /* start of arg list */
Then, each call to
nxtarg
will fetch the next argument:
-
argument = nxtarg (&pointer,"delimiters");
Each call to
nxtarg
will space the pointer up to one of the
delimiters or the end of the string, whichever comes first.
Then, the string will be chopped into two pieces: the part
containing the argument just parsed, and the rest of the string.
The address of the first part will be returned; the pointer
will be left pointing to the second part, all ready for the
next call to
nxtarg.
Note that the pointer must not be in a register, since it
is passed by address.
The delimiter character (or null character at the end of the string)
encountered is placed into the external variable called,
_argbreak.
You may look at this value to see what delimiter was encountered.
If no delimiters were encountered before the end of the string,
then the null character will be placed into
_argbreak.
If
brk,
the list of break characters, is 0, then the space character will
be used as the only delimiter.
SEE ALSO
scanf(3),
boolarg(3),
intarg(3),
stabarg(3),
strarg(3),
etc.
DIAGNOSTICS
If the argument points to the null string,
or the end of the string is reached,
then a pointer to the null string will be returned.
At the
end of the string,
nxtarg()
may be repeated any number of
times -- it will continue to leave the pointer unchanged,
and return a pointer to the null string.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- SEE ALSO
-
- DIAGNOSTICS
-
This document was created by
man2html,
using the manual pages.
Time: 11:12:47 GMT, November 04, 2022