| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

getstrfldlen

#include "sflstr.h"
int
getstrfldlen (
    char *strbuf,
    int fldno,
    int ofset,
    char *sep)

Synopsis

Get the length of as a field in a string. Used mainly for getting the len to malloc mem to call getstrfld with. Returns the length of the field. Submitted by Scott Beasley jscottb@infoave.com

Source Code - (sflstr.c)

{
   char *offset, *strptr;
   int curfld, retlen = 0;

   ASSERT (strbuf);
   ASSERT (sep);

   offset = strptr = (char *)NULL;
   curfld = 0;

   strbuf += ofset;

   while (*strbuf)
     {
       strptr = !offset ? strbuf : offset;
       offset = strpbrk ((!offset ? strbuf : offset), sep);

       if (offset)
          offset++;
       else if (curfld != fldno)
         {
           retlen = 0;
           break;
         }
       if (curfld == fldno)
         {
           retlen = (int)(!offset ? strlen (strptr) + 1 :
                    (int)(offset - strptr));
           break;
         }
       curfld++;
     }
   return retlen;
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation