string manipulation

Chad Gibbons chad at lakesys.UUCP
Mon Sep 26 10:04:58 AEST 1988


        For several applications it would become necessary to remove a small
string from a larger one. There appears to be an easy way to do this, and here
is a sample piece of code I was testing :

    char *squeeze(cs, ct)
        const char cs[];
        const char ct[];
    {
        register int i;
        int j,x;

        j = strcspn(cs, ct);
        for (i = j; cs[i] != '\0'; i++)
            cs[i] = cs[i + x];
        return (char *)s;
    }
It seems the algorithm should work. However, if nothing else is wrong, one
basically major thing is: you cannot over step the array bounds. If you do,
you get a nifty little core dump error. So, I'm looking for a good way to do
this. I tried it with pointers, but I had worse luck than with this. For all
I know there is some obscure library function to do this, but I didn't find
one in our library. Any one have a better way to do it? Post it, inform us
all. I'm curious to see if this can be done with explicit pointers and not
just with array indexes.



More information about the Comp.lang.c mailing list