Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Aug 1997 15:58:38 -0400 (EDT)
From:      Thomas David Rivers <ponds!rivers@dg-rtp.dg.com>
To:        domenic@aix.can.ibm.com, ponds!FreeBSD.ORG!questions
Subject:   Re: coding...
Message-ID:  <199708221958.PAA03915@lakes.dignus.com>

next in thread | raw e-mail | index | archive | help
> 
> hi folks,
> 	I know....there is no gcvt and basename functions available...
> 	I am trying to port code over to FreeBSD and I cant find equivalents.
> 	any takers ?
> thanks,
> domenic
> -- 

 For a 'dumb' gcvt() (you'd really want to check string sizes, etc..)
you can use sprintf(), e.g.

  gcvt(d, n, str)

becomes:

	sprintf(str,"%f", d);

[you can get really fancy with the format specification and handle
the number of digits, etc... I'll leave that up to the reader...]



 Here's a basename() function - this returns a pointer
within the original string - so don't modify the result
pointer...

char *
basename(string)
char *string;
{
        char *start_of_basename;

        start_of_basename = string + (strlen(string) - 1);
        while(start_of_basename != string) {
                if(*start_of_basename == '/') {
                        break;
                }
                start_of_basename --;
        }

        if(start_of_basename == string) {
                /* Didn't find anything */
                return start_of_basename;
        } else {
                /* Bump past the '/' and return a pointer */
                /*  to the basename. */
                if(*start_of_basename == '/') start_of_basename++;
                return start_of_basename;
        }
}



	- Dave Rivers -



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708221958.PAA03915>