#include<stdio.h>
#include<string.h>
int main()
{
        char *s1[7]="hello1";     // 5
        char *s2[7]="hello2";     // 6
        {
              strcpy(s1, s2);        // 8       
               printf("%s\n", s1, s2);
        }
}


7-26C++.cpp: In function `int main()':
7-26C++.cpp:5: invalid initializer
7-26C++.cpp:6: invalid initializer
7-26C++.cpp:8: cannot convert `char**' to `char*' for argument `1' to `char*
   strcpy(char*, const char*)'


--- On Sat, 7/26/08, Oliva Lukas <[EMAIL PROTECTED]> wrote:
From: Oliva Lukas <[EMAIL PROTECTED]>
Subject: Re: [c-prog] Segmentation fault
To: [email protected]
Date: Saturday, July 26, 2008, 11:11 AM










    
              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.CubicleS oft.com/MyTaskFo cus/

> 


      

    
    
        
         
        
        








        


        
        


      

[Non-text portions of this message have been removed]

Reply via email to