Eugene Romm <[EMAIL PROTECTED]> writes:

> I've written a procedure that's supposed to remove all occurances of
> string2 from string1 (parameters).

I'd use sth like strstr(3) for that... Is it homework?

> Segfault occurs on line 29, as far as I can tell.

And that would be

         if (factor!=0) s1[c1]=s1[c1+factor];

I guess, where you attempt to write into s1. You passed a string
literal ro squeezechar2(), and that's a const. Think: main() only
knows of a const string "abcdeFghijklmnopqrstuvwxyZ", and passes
a pointer to it (don't let the "char s1[]" form of the argument
confuse you - it is a pointer that is passed, see the comp.lang.c FAQ)
to squeezechar2(). The latter is not allowed to write into the memory
pointed to. 

> main() {
>   squeezechar2("abcdeFghijklmnopqrstuvwxyZ","deF");
> }

int main(void) { /* yes, int main() and C-style comments... */
    char s1[] = "abcdeFghijklmnopqrstuvwxyZ";
    return squeezechar2(s1,"deF");
}

> squeezechar2(s1,s2)
>      char s1[];
>      char s2[];

I thought nobody used traditional C nowadays...
 
OK, there goes your homework, but this is absolutely, positively the
last time... ;-) Next time, please post to comp.lang.c or something of
the kind (this is not a C list), tell them what you tried, and do read
the FAQ before you post. Thanks,

-- 
Oleg Goldshmidt | [EMAIL PROTECTED] 
If it aint't broken it hasn't got enough features yet.

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

  • C p... Eugene Romm
    • ... Max Kovgan
    • ... Vlad
    • ... Oleg Goldshmidt
    • ... Yaacov Fenster - System Engineering Troubleshooting and other miracles
    • ... Behdad Esfahbod

Reply via email to