Hi,
Your program has a few bugs (beside the style problems):
1. It just does not work when there is more than one occurence of s2
in s1, because you are just moving s1[c1+factor] to s1[c1], and the
matching of s1+c1 with s2 cannot be performed at the same time.
2. s1[c1+factor] can reach beyon
By default, string constants are put into read only memory pages. You
are getting a SEGV when you try to modify one by s1[c1]=s1[c1+factor];
You can "workaround" it by using the -fwritable-strings in gcc or
something similar in a different c/c++ compiler. However the best way is
to copy the const
you're right ..according to this given example,
it's a constant string, so it is inside the executable,
and is read only,and when gdb runs the binary,
it probably opens it in other (protected)
memory space in writeable mode.
but i'll try to protect my statement :
if the string is accepted not as
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!
the problem here isn't a buffer overflow, i'm afraid. the problem here
is that s1 and s2 are in a read only section of the executable, and
trying to modify s1 is forbidden.
consider this snippet, which produces a SIGSEGV as well:
void foo(char s[]){
s[0] = 'b';
}
int main()
{
foo("a");
Try to learn about pointers and function calls in C
it's basic error : when you try to pass to function string not in variable
like char* or char[] and try to modify it
error-->"squeezechar2("abcdeFghijklmnopqrstuvwxyZ","deF");"
solution is to define string that you will modify in function like
this line:
if (factor!=0) s1[c1]=s1[c1+factor];
tries to see behind the s1's end after the index (length_of_s1 - factor)
is reached.
this causes SIGSEG
it's not nice to ask people to debug your own homework :))
bye
-=O0~~O0=-
"Beware the Jabberwock, my son!
The j
Hello.
I've written a procedure that's supposed to remove all occurances of
string2 from string1 (parameters).
For reasons I do not understand, the program compiles but segfaults when
run from the command prompt, but silently executes without a warning
when run under GDB. Attached is the progr