Rob-

You don't need to allocate additional space for the null char. This
works fine for me:

static int __inline TBPGetString(PChar src, PChar dest, int size)
{
        int     nRetVal=0;

        if (NULL != src)
                nRetVal = lstrlen(src);
        if ((NULL != dest) && (size > 0))
        {
                if (size > nRetVal)
                        size = nRetVal;
                if (size > 0)
                {
                        lstrcpy(dest, src);
                        nRetVal = size;
                }
        }
        return (nRetVal);
}

Monday, January 20, 2003, 5:19:47 PM, you wrote:


RR> Monday, January 20, 2003, 8:08:28 PM, you wrote:

RR> So far this is what I'm using for my GetString.  I think this is
RR> correct, and it appears to be working fine:
RR> ---
RR> int GetString(char *src, char *dest, int size) {
RR>     if (dest==NULL || size<=0) return lstrlen(src);
RR>     if (size>lstrlen(src)) size = lstrlen(src);
RR>     if (size>0) {
RR>         lstrcpyn(dest,src,size+1); // (size+1) = (size) + (null character)
RR>         return size;
RR>     }
RR>     return 0;
RR> }

-Mark Wieder

 Using The Bat! v1.63 Beta/4 on Windows 2000 5.0 Build 2195 Service Pack 2
-- 


________________________________________________
Current version is 1.62 | "Using TBDEV" information:
http://www.silverstones.com/thebat/TBUDLInfo.html

Reply via email to