hi,
The pseudo-code for my C function is this :
getwsfield locates the specified field in the string s,
* where a field is a non-empty string surrounded by white space.
* The field is copied to buf, which has room for buflen bytes
* (including a terminating '\0'). Buflen must be at least 1.
* If the field doesn't exist, an empty string is placed in the buffer.
* If copy_to_end is false, only the requested field is copied,
* otherwise the rest of the string from the specified field onwards is copied.
*/
So far i have managed to get this far:
#include <ctype.h>
#include <string.h>
void getwsfield(char *s, int fieldnum, Bool copy_to_end,
char *buf, int buflen)
{
char *sp; /* Cursor to identify fields in s */
sp = s;
while (isspace(*sp))
sp++;
}
I have therefore managed to use the isspace function to skip to the start of the first field.
However, i need to write a loop that skips unwanted fields, so that for a specified field number, the loop skips all the fields preceding it - eg field number 3 required - skip 2 fields.
So the loop needs to skip to next space (or end of string)
and skip over spaces between fields
for (nf=1; nf < fieldnum; nf++) {
}
what should be the contents of the above loop?
thanks.