Maybe to be more specific,
you should use array of chars for string representation, so for "hello",
char s1[7] = "hello";
should be used.
Lukas Oliva
On Fri, Jul 25, 2008 at 07:42:16PM -0700, Thomas Hruska wrote:
> Robert Ryan wrote:
> > #include<stdio.h>
> > #include<string.h>
> > int main()
> > {
> > char *s1="hello1" ;
> > char *s2="hello2" ;
> > {
> > strcpy(s1, s2);
> > printf("%s\n" , s1);
> > }
> > }
> >
> > [EMAIL PROTECTED] ~/CSSp08]$ ./a.out
> > Segmentation fault (core dumped)
>
> That is because the memory of s1 and s2 are _read only_. The pages are
> flagged by the OS as read-only. Attempting to write to a read only page
> results in an exception being raised. In other words, accept that the
> above is something you should NOT do and live with it.
>
> (There are ways to force pages of RAM to be read-write under all major
> OSes, but such is outside the scope of this group, the methods are
> non-ANSI Standard, and involve advanced OS topics where you only use
> such methods when you really, truly know what you are doing not just
> with C/C++ but with the OS itself).
>
> --
> Thomas Hruska
> CubicleSoft President
> Ph: 517-803-4197
>
> *NEW* MyTaskFocus 1.1
> Get on task. Stay on task.
>
> http://www.CubicleSoft.com/MyTaskFocus/
>