code:

Can't Copy and Paste this?

Click here for a copy-and-paste friendly version of this code!

 

Terms of Agreement:   

By using this code, you agree to the following terms...   

1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   

2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   

3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 

4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.  

/* +++Date last modified: 05-Jul-1997 */

#include 

#include 

#include "snip_str.h"

#if defined(__cplusplus) && __cplusplus

    extern "C" {

    #endif

    char *sstrdel(char *s, ...)

        {

        /* Find out how many arguments are present */

        int c = 0;

        va_list ap, hold;

        if (s == NULL)

        return NULL;

        va_start(ap, s);

        memcpy(&hold, &ap, sizeof(va_list));

        while (va_arg(ap, char*) != NULL)

        c++;

        va_end(ap);

        if (c)

            {

            /* Assign pointers */

            char *r = s,*n = s; 

            char *p;

            int len, i;

            /* Copy next character to result */

            /* And then check for matches if */

            /* not at end of string */

            while ((*r = *n) != 0)

                {

                int l = 0;

                /* Substitute for va_start(ap,s) */

                memcpy(&ap, &hold, sizeof(va_list));

                for (i = 0; i < c; i++)

                    {

                    /* Initialise the pointer and the length*/

                    len = strlen(p = va_arg(ap, char*));

                    /* Compare ONLY if we haven't found one yet */

                    /* or if this one is bigger than the one we */

                    /* found AND this arg has a length > 0 */

                    if(len > 0 && (l == 0 || len> l) &&

                    strncmp(n, p, len) == 0)

                        {

                        l = len;

                    }

                }

                va_end(ap);

                if (l)

                n += l;

                else n++, r++;

            }

        }

        return s;

    }

    #if defined(__cplusplus) && __cplusplus

}

#endif

#ifdef TEST

#include 

main()

    {

    char *testr = "The quick brown fox jumps over the lazy dog.";

    char *s1 = "quick", *s2 = "over", *s3 = "lazy";

    char *s4 = "he", *s5 = "xyz";

    printf("sstrdel(\"%s\",\"%s\",\"%s\",\"%s\")\n returned ",

    testr, s1, s2, s3);

    printf("\"%s\"\n", sstrdel(testr, s1, s2, s3, NULL));

    printf("sstrdel(\"%s\",\"%s\",\"%s\")\n returned ",

    testr, s4, s5);

    printf("\"%s\"\n", sstrdel(testr, s4, s5, NULL));

    return 0;

}

#endif /* TEST */